How does javascript forEach() function work in mongodb shell?
With what sequence are the documents being processed?
Eg, let's say that I have two big collections and those two collections should contain the same number of documents (note that the structure of the document isn't necessarily the same), and I want to iterate the first and see if for each document in the first collection, there's a record for it in the second collection :
db.MyColl.find().forEach(
function(aDocument) {
print("Checking :"+aDocument._MyId)
var db2 = db.getSiblingDB("mySiblingDb");
var aDocument2 = db2.MyColl.findOne({_MyId: aDocument._MyId});
if (aDocument2 == null) {
print("Missing document with _MyId: " + aDocument._MyId);
}
}
);
Is this piece of code going to iterate the documents with the same sequence?