e-oj / Fawn

Transactions for MongoDB (See the README)
https://www.npmjs.com/package/fawn
MIT License
486 stars 54 forks source link

Dynamic number of updates #80

Closed avillarubia closed 4 years ago

avillarubia commented 4 years ago

Good day,

Question

is it possible to loop multiple updates like this?

    Fawn.init(mongoose) <--initiliazed above

    .
    ..
    ...
    const task = new Fawn.Task()

    updates.map(({ _id, row }) => {
      task.update("accounts", { _id: _id }, { row: row })
    })

    task.run({ useMongoose: true })

I tried it but it does not work, tried also by async but doesn't work. Hoping that you guys encounter this case and solved it.

Thank you.

prasad1120 commented 4 years ago

Use { $set: { row: row} } instead of { row: row } and check if _id is required as mongoose.Types.ObjectId(_id).

Also, looks like this library is dead. Quite a few issues with it and no new releases since the early 2018. Best to avoid it.

avillarubia commented 4 years ago

@prasad1120 thank you for the response. Do you have any recommendations like this?