What is the difference between the cursor.count() and cursor.size() methods of MongoDB's DBCursor?
What is the difference between the cursor.count() and cursor.size() methods of MongoDB's DBCursor?
When I first read the documentation on the difference between cursor.count and cursor.size, I was similarly stumped b/c I didn't understand what it meant to not consider skip or limit. I found this article to be helpful read more here. I think the following example illustrates the differences
// by default cursor.count ignores limit or skip. note that 100 records were returned despite the limit being 5
> db.restaurants.find( { "cuisine": "Bakery", "address.zipcode": "10462" } ).limit(5).count();
100
// if you want to consider limits and skips, then add an optional parameter specifying so
> db.restaurants.find( { "cuisine": "Bakery", "address.zipcode": "10462" } ).limit(5).count(true);
5
// cursor.size on the other hand abides by limits and skips
> db.restaurants.find( { "cuisine": "Bakery", "address.zipcode": "10462" } ).limit(5).size();
5