Does MongoDB's $in clause guarantee order

后端 未结 10 1255
春和景丽
春和景丽 2020-11-22 01:39

When using MongoDB\'s $in clause, does the order of the returned documents always correspond to the order of the array argument?

10条回答
  •  广开言路
    2020-11-22 02:19

    I know this is an old thread, but if you're just returning the value of the Id in the array, you may have to opt for this syntax. As I could not seem to get indexOf value to match with a mongo ObjectId format.

      obj.map = function() {
        for(var i = 0; i < inputs.length; i++){
          if(this._id.equals(inputs[i])) {
            var order = i;
          }
        }
        emit(order, {doc: this});
      };
    

    How to convert mongo ObjectId .toString without including 'ObjectId()' wrapper -- just the Value?

提交回复
热议问题