Skip to content

Commit

Permalink
Fixed update and added bulk updates on cs_data_processor.
Browse files Browse the repository at this point in the history
  • Loading branch information
riclolsen committed Jun 13, 2024
1 parent 3e66ce4 commit 72e5ac0
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/cs_data_processor/cs_data_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,38 @@ const pipeline = [
}, 17317)

setInterval(async function () {
if (!collection || !MongoStatus.HintMongoIsConnected) return
if (
!collection ||
!MongoStatus.HintMongoIsConnected ||
mongoRtDataQueue.isEmpty()
)
return
let cnt = 0
let updArr = []
while (!mongoRtDataQueue.isEmpty()) {
let upd = mongoRtDataQueue.peek()
delete upd._id // remove _id for update
collection
.updateOne(
{ _id: upd._id },
{
$set: upd,
},
{
writeConcern: {
w: 0,
},
}
)
.catch(function (err) {
Log.log('Error on Mongodb query!', err)
})
const upd = mongoRtDataQueue.peek()
mongoRtDataQueue.dequeue()
const _id = upd._id
delete upd._id // remove _id for update
updArr.push({
updateOne: {
filter: { _id: _id },
update: { $set: upd },
},
})
cnt++
}
const res = await collection
.bulkWrite(updArr, {
ordered: false,
writeConcern: {
w: 0,
},
})
.catch(function (err) {
Log.log('Error on Mongodb query!', err)
})
// Log.log(JSON.stringify(res))
if (cnt) Log.log('Mongo Updates ' + cnt)
}, 150)

Expand Down

0 comments on commit 72e5ac0

Please sign in to comment.