findAndModify Error in mongodb - nodejs - error code 17287

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);
    });

}

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/