2

和尚的mongo等价代码是什么?

use challenger_documents
db.question.find({_id: {$in: [ObjectId("56587ad1c30ea73eb22546f0"), ObjectId("5659779b5eb5a70f35db8125")]}})

例如,我尝试了这个,但它返回 []:

var mongodb = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/challenger_documents');
question = db.get("question")
question.find({_id:{$in:["5659cba1ef72b7ef523206c5"]}},{},function(e,d){console.log(d)})
4

1 回答 1

0

您需要将_id字符串转换为ObjectId

var mongodb = require('mongodb'),
    monk = require('monk'),
    db = monk('localhost:27017/challenger_documents'),
    ObjectId = mongodb.ObjectID,
    question = db.get("question");

question.find({_id: { $in: [ ObjectId("5659cba1ef72b7ef523206c5") ] } },{},function(e,d){ console.log(d) });
于 2015-11-28T17:56:18.057 回答