问题
I am getting following error :
MongoError: exception: nextSafe(): { $err: "Can't canonicalize query: B adValue bad sort specification", code: 17287 }
functions.getNextIndex = function(callback){
db.collection('counters').findAndModify(
{_id:'productId'},
{$inc: {sequence_value:1}},
function(err,data){
if(!err)
callback(data);
else
callback(err);
});
}
回答1:
It seems you are missing the "sort" argument in your query.
Try something like:
db.collection('counters').findAndModify(
{_id:'productId'},
{_id:'descending'},
{$inc: {sequence_value:1}},
function(err,data){
if(!err)
callback(data);
else
callback(err);
});
See more here: http://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/
来源:https://stackoverflow.com/questions/25771052/findandmodify-error-in-mongodb-nodejs-error-code-17287