I am using db.system.js.save
to save js functions on the server.
I wrote this script so far
function () {
cursor = db.MyCollection.find({_id: {$in:[arguments]}})
^ this does not work
while(cursor.hasNext()){print(cursor.next())};
}
I am calling it with the following argument findAllDocuments(ObjectId("544a30c80c80d5809180b"),<more objects>);
, but it is not working.
Do I have to call it arguments
differently? Because arguments[0]
is working for example.
Edit: For clarification arguments
are the parameters of the javascript function.
findAllDocuments(ObjectId("544a30c80c80d5809180b"),ObjectId("544a30c80c80d5809180b"), <and more objectIds>);
If I use it like this it does work, but the arguments length can be variable.
function () {
cursor = db.MyCollection.find({_id: {$in:[arguments[0],arguments[1]}})
^ this does work
while(cursor.hasNext()){print(cursor.next())};
}
EDIT 2:
How can I use the $in correctly in $ref?
cursor = db.MyCollection.find({"trainer" : {
"$ref" : "Contact",
"$id" : {$in : [ObjectId("556d901118bfd4901e2a3833")]}
^it executes successfully, but does not find anything
}})