e-oj / Fawn

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

multi option does not appear to be working. #15

Closed thedanielfactor closed 7 years ago

thedanielfactor commented 7 years ago

The following snippet of code works fine without the {multi:true} option but as soon as I add it something fails. It does not hit the catch and it does not return anything to the client.

task.update("UserPresence", {sessionId: req.params.sessionId}, {sessionId: null})
                            .remove("GroupSession", {_id: req.params.sessionId})
                            .options({multi:true})
                            .run({useMongoose: true})
                            .then(function () {
                                res.send({message: "session " + req.params.sessionId + " has ended"});
                            }).catch(function (err) {
                                res.send(err);
                            });

node 6.11.1 mongoose 4.11.6 fawn 2.0.1

e-oj commented 7 years ago

The remove function doesn't accept options. It removes all matching docs by default

e-oj commented 7 years ago

The catch handles errors that occurred during the run. Attaching options to remove throws an error immediately and synchronously so the task never runs. But it should throw an error

e-oj commented 7 years ago

That said, I have considered adding the multi option to the write functions because both the driver and mongoose have implemented one/many functions (updateOne, removeMany, .. etc) for all write operations. If you feel that would be a useful feature, I can tag this as an enhancement and it will be implemented in the next release. @thedanielfactor

thedanielfactor commented 7 years ago

Ah, so I need to add the options to the update. That is where I wanted it. I am not sure why I put it on the remove. I will try that.

thedanielfactor commented 7 years ago

I do like the one/many idea. That would be useful.