scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

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

Open royaltm opened 8 years ago

royaltm commented 8 years ago

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 commented 8 years ago

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

scottwrobinson commented 8 years ago

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!

senthilprabhut commented 7 years ago

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?