-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
Affects Version/s: 1.6.0
-
Component/s: AsyncWriter
-
None
-
Needed
-
I try to migrate my scripts to new mongosh, but is seems to be still a nightmare...
I have a logging framework like this:
class Logger { constructor(logId) { Object.defineProperty(this, 'logId', { value: logId }); Object.defineProperty(this, 'action', { value: -1, writable: true }); } set Command(cmd) { db.logging.updateOne({ _id: this.logId }, { $set: { [`action.${this.action}.command`]: cmd } }); } unsetCommand(i, duration) { db.logging.updateOne({ _id: this.logId }, { $set: { [`action.${i}.duration`]: duration }, $unset: { [`action.${i}.command`]: null } }); }} var doc = db.logging.insertOne({ script: "updateStats", timestamp: ISODate(), action: [], state: 'running' }); var logger = new Logger(doc.insertedId); for (let i = 0; i < 10; i++) { db.logging.findOneAndUpdate({ _id: logger.logId }, { $push: { action: { ts: ISODate(), name: "connectReplicaSet" } } }); logger.action = i; logger.Command = `command #${i}`; logger.unsetCommand(i, 11); } db.logging.updateOne({ _id: logger.logId }, { $set: { duration: 123, state: 'success' } }); db.logging.findOne({ _id: logger.logId }).action.filter(x => x.command !== undefined)
The last command {{db.logging.findOne(
{ _id: logger.logId }).action.filter(x => x.command !== undefined)}} typically returns a few documents, i.e. {{$unset: { [`action.${i}.command`]: null } }} did not work.
Typically on 20-50% of the commands the update is not written to database.
I tried with different writeConcern and {{(async () =>
{ db.logging.updateOne(...) })()}} but none of them is working reliable. In legacy mongo shell it is always working fine.
Any suggestions?
Wernfried Domscheit