e-oj / Fawn

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

update array of documents is not working #59

Closed coyksdev closed 6 years ago

coyksdev commented 6 years ago

I'm trying to update one of the embedded document inside the array. when i use na native mongodb command (update) it works but when i use the fawn transaction it is not working.

This is the document in the collection named Post, I want to update the image link by finding the post _id and image _id.

{ "_id": ObjectId("5b0620186ba2be2cb7390e8c"), "type" : "event", "title" : "yeah",
"images" : [ { "_id" : ObjectId("5b061f9f6ba2be2cb7390e8b"), "link" : "this is the link" } ], }

this is my update command

const image = { _id: ObjectId("5b061f9f6ba2be2cb7390e8b"), link: "updated link" }

transaction.update( "Post", { _id: : ObjectId("5b0620186ba2be2cb7390e8c"), 'images._id': ObjectId("5b061f9f6ba2be2cb7390e8b") }, { $set: { 'images.$': { ...image } } } ).run();

it doesn't update the document

e-oj commented 6 years ago

Does it throw an error?

coyksdev commented 6 years ago

it doesn't throw any error it just not update the embedded document

e-oj commented 6 years ago

Does it work if you run it without Fawn?

coyksdev commented 6 years ago

yeah it works when used Model.update() or Model.findOneAndUpdate() in mongoose

e-oj commented 6 years ago

I haven't been able to reproduce this issue. Can you provide a running snippet of code with this issue? Thanks.

e-oj commented 6 years ago

I'll close this for now. If you're successful in reproducing the issue, feel free to reopen it.

Mizero-eloi commented 2 years ago

I have the same issue when I try to update the array document It does not throw an error it simply doesn't update

try{ await new Fawn.Task() .update("challenges", {_id: mongoose.Types.ObjectId(req.params.challengeId)}, { $push: { participants: { name: participant.username, profile: participant.profile } } }) .run({useMongoose: true});

}catch(ex){ console.log(ex); }