Anders Östman
Anders Östman

Reputation: 3832

findAndModify in Mongoskin

I cant get findAndModify to work with Mongoskin! This is probably dead simple, but what is wrong with this line?

var projections = {company: 1, ...};
db.clients.findAndModify({demo: false}, projections, {$set: {sms_sent: 0}}).toArray(function(err, docs) { 
... }

I get thrown a 'TypeError: object is not a function'.

Upvotes: 0

Views: 938

Answers (1)

Leonid Beschastny
Leonid Beschastny

Reputation: 51500

findAndModify is not returning cursor, so instead of calling .toArray() you should pass your callback directly as the last argument of findAndModify see node-mongodb-native docs:

collection.findAndModify(query, sort, update, options, callback)

Or, in your case:

db.clients.findAndModify({
  demo: false
}, projections, {
  $set: { sms_sent: 0 }
}, function(err, doc) { 
  // doc is a single document, not an array
}

Upvotes: 1

Related Questions