【发布时间】:2015-06-02 21:36:32
【问题描述】:
我正在使用db.system.js.save在服务器上保存js函数。
到目前为止,我编写了这个脚本
function () {
cursor = db.MyCollection.find({_id: {$in:[arguments]}})
^ this does not work
while(cursor.hasNext()){print(cursor.next())};
}
我使用以下参数findAllDocuments(ObjectId("544a30c80c80d5809180b"),<more objects>); 调用它,但它不起作用。
我必须以不同的方式称呼它arguments吗?因为arguments[0] 例如正在工作。
编辑:澄清arguments是javascript函数的参数。
findAllDocuments(ObjectId("544a30c80c80d5809180b"),ObjectId("544a30c80c80d5809180b"), <and more objectIds>);
如果我像这样使用它,它确实可以工作,但参数长度可以是可变的。
function () {
cursor = db.MyCollection.find({_id: {$in:[arguments[0],arguments[1]}})
^ this does work
while(cursor.hasNext()){print(cursor.next())};
}
编辑2:
如何在 $ref 中正确使用 $in?
cursor = db.MyCollection.find({"trainer" : {
"$ref" : "Contact",
"$id" : {$in : [ObjectId("556d901118bfd4901e2a3833")]}
^it executes successfully, but does not find anything
}})
【问题讨论】: