amark / mongous

Simple MongoDB driver for Node.js with jQuery like syntax.
MIT License
246 stars 30 forks source link

More than 100 records. #15

Closed leanderlee closed 12 years ago

leanderlee commented 12 years ago

For some reason when I do a find or any type of query that returns more than 100 records, it returns in the reply object:

"startingFrom":101 and only one object.

How do I get the previous results?

leanderlee commented 12 years ago

Ohhh I got it. So apparently the callback gets called twice. as opposed to returning when complete...

How do you know when it's finished sending results?

leanderlee commented 12 years ago

Oh okay. there's a more: true.

This stuff needs to get documented.

amark commented 12 years ago

the callback returns in streaming chunks of a 100 objects.

So if you have 650 objects, the callback will get called 6 times.

If there are more values the return object will have a "more" property. So you can test for that, here is an example:

mon('database.collection').find(function(p){ if(p.documents.length) { for (var i in p.documents) { // do something with the object } } if(!p.more) { //finished } });

Please let me know if that works, feel free to ask anything else.

leanderlee commented 12 years ago

Yep. I figured it out. Normally I wouldn't have opened an issue but it was rather mission critical.