RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range on a "find" query

I am running a find command (using node) against my mongodb Atlas cluster. The query is supposed to return in the neighborhood of 1.3 mil records. But I get this error:

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 && <= 17825792. Received 17825801
    at Buffer.write (buffer.js:1052:5)

Here is my code:

    .populate('lead', '-_id fname lname email phone city state zip ip')
    .then(leads => {
        console.log('Done', leads.length);
    .catch(e => {

From what I understand, that error is thrown when you try to insert a document larger than 16M into your database. But I am not doing that. I am just running a find command. What am I missing here?

Hi @Zarif_Alimov,

Just wondering if you’re still having issues with this? If so, could you share further details regarding the query portion of your code snippet as well as the MongoDB version in use? (Redact any personal or sensitive information before posting here)


Changing the code to use .aggregate instead of .find fixed the issue. No clue why to be honest.

1 Like

Thanks for advising the fix and glad to hear it was resolved Zarif. Would you be able to provide the query value of the code? I would like to see if I could replicate the error.