According to MongoDB manual, the below code exhausts the array and stores the the docs returned by the query to RAM:
var myCurse = db.coll.find();
var docs = myCurse.toArray()
If I type in the command :
myCurse.forEach(printjson);
after the first two commands, nothing is returned. So basically the cursor has been exhausted. All looks good here.
Now if do the below:
var myCurse = db.coll.find();
myCurse.toArray()[1];
and then:
myCurse.toArray()[2];
I still get results.
My questions are:
- does
myCurse.toArray()[i];whereiis an index, implement an array underneath so thatmyCurse.toArray()[i];can be utilized multiple times. - How long do the documents get stored in RAM?
- What happens if size of returned documents exceeds RAM size?
Using MongoDB 3.2.8