findAndModify Error in mongodb - nodejs - error code 17287

纵饮孤独 提交于 2019-12-11 09:48:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!