camo icon indicating copy to clipboard operation
camo copied to clipboard

Support for $inc, $push, $addToSet, $pop, $pull update methods in loadOneAndUpdate.

Open royaltm opened this issue 9 years ago • 3 comments

Currently there is no easy way to make use of those atomic updates to underlying documents. Perhaps it would be easy to enhance Document.prototype.loadOneAndUpdate in such a way:

MyDoc.loadOneAndUpdate(query, {somePropToIncrement: 2}, {update: "inc"}) so the client implementation would be such like:

var update = options.update || "set";
db.findOneAndUpdate(query, {[`$${update}`]: values}, options);

royaltm avatar Feb 06 '16 14:02 royaltm

do you consider accepting pull requests? didn't find anything about contribution

royaltm avatar Feb 27 '16 09:02 royaltm

Sorry for not getting back to you sooner on this.

To answer your question, yes, I do accept pull requests (I'll update the README to better reflect this). Do you have one ready? If not, I should be able to get to this feature within the next few days.

Thanks!

scottwrobinson avatar Mar 01 '16 21:03 scottwrobinson

I see this being listed for milestone 0.13.0 Are you planning to release 0.13.0 in the near future?

I'm using 0.12.3 and I have the following query executed Stats.findOneAndUpdate({'myid': myID},{$push: {'stats': stats } },{upsert: false, new: true})

and I keep getting the error message name: 'MongoError', message: 'exception: The dollar ($) prefixed field '$push' in '$push' is not valid for storage.',

Is the error because of the feature being not available in 0.12.3?

senthilprabhut avatar Dec 05 '16 06:12 senthilprabhut