I checked the monk's source code and finally did it. Even the code documentation says how it should be, but it is not visible from the documentation on the coin.
/** * findAndModify * * @param {Object} search query, or { query, update } object * @param {Object} optional, update object * @param {Object|String|Array} optional, options or fields * @param {Function} callback * @return {Promise} * @api public */
This means that you can specify the request and update as separate parameters, as well as options as the third parameter:
notescollection.findAndModify( { "_id": id }, { "$set": { "title": title, "content": content }}, { "new": true, "upsert": true }, function(err,doc) { if (err) throw err; console.log( doc ); } );
Or you can specify the request and update as the fields of the first parameter, as well as parameters as the second parameter:
notescollection.findAndModify( { "query": { "_id": id }, "update": { "$set": { "title": title, "content": content }} }, { "new": true, "upsert": true }, function(err,doc) { if (err) throw err; console.log( doc ); } );
For more information about sources, check findAndModify in the collections.js file.
Roman
source share