amark/mongous — Issue #18: find method when there are more than 500 records
Author: acsaga
Created: 2012-02-09 06:09:31+00:00
State: open

find method will trigger the callback function multiple times if there are more than 500 records. I think it's a bug.

in find:

if (msg.more && o.lim == 0) {
//lim = o.lim - it < 500 ? 500 : o.lim - it;
this.more(cmd.collectionName, 500, msg.cursorID, id);
} else {
con.c.removeListener(id.toString(), con.c.listeners(id.toString())[0]);
}
if (fn) {
return fn(msg);
}

I think it should be:

if (msg.more && o.lim == 0) {
//lim = o.lim - it < 500 ? 500 : o.lim - it;
this.more(cmd.collectionName, 500, msg.cursorID, id);
} else {
con.c.removeListener(id.toString(), con.c.listeners(id.toString())[0]);
if (fn) { /* move the callback inside the 'else' */
return fn(msg);
}
}

how do you think about it?