marcello3d / node-mongolian

[project inactive] Mongolian DeadBeef is an awesome Mongo DB driver for node.js
https://groups.google.com/group/node-mongolian
zlib License
350 stars 50 forks source link

findandmodify example? #26

Closed Taler-zz closed 13 years ago

Taler-zz commented 13 years ago

I want to find a document, update it, and return it. Your documentation is a tad unclear.

Trying this:

collection.findAndModify( {query: {comment:'0'}, update : {"$inc":{"count":1}}, 'new': true}, function (doc) {
  console.log(doc)
})
marcello3d commented 13 years ago

The intention is for the findAndModify to match the mongodb shell with node.js-style function(err,result) callbacks. Most of the method documentation is word-for-word from Mongo's shell documentation.

In this case it looks like your code is correct except for the callback should have an error argument first.

I must admit I haven't used findAndModify myself (I'm just passing the arguments to the mongodb server based on their mongo shell code and driver spec). If you do get it working, a unit test or even just a documentation example would be greatly appreciated.

Taler-zz commented 13 years ago

Oh that works just fine. Gracias.

Attempt at doc.