I have been trying to get code in callback executed for couple of days now but am I not sure what I am doing wrong. Following is the code which I am trying to execute. For some reason callback is not getting executed even though the sequence is getting incremented.
Please help.
var seqCollection = new mongodb.Collection(client, 'seq');
seqCollection.findAndModify(
{"_id": "name"}, [], {$inc: {"seq": 1}}, {},
function (err, result) {
if (err){
console.log('--------- There is a an error ------------');
} else{
console.log('--------- New Value:' + JSON.stringify(result) + '------------');
}
});
you should not use new Collection
use
db.collection("seq").findAndModify(....)
also docs are here
http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#findandmodify
Was able to find the problem .....
client.close();
was misplaced in the code.