RangeError in aggregation

Hello! I encountered an error while executing this MongoDB aggregation with nodejs:

[
    {
        "$match": {
            "_id": {
                "$in": <JavaScript array of billion ObjectId>
            }
        }
    },
    {
        "$facet": {
            "nbSession": [
                {
                    "$group": {
                        "_id": "$sessionId"
                    }
                },
                {
                    "$count": "count"
                }
            ],
            "nbUser": [
                {
                    "$group": {
                        "_id": "$userId"
                    }
                },
                {
                    "$count": "count"
                }
            ]
        }
    }
]

The error I received is as follows:

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 && <= 17825792.

Could someone please help me understand and resolve this issue? Thank you in advance!

Hello @hoc_Tac ,

Welcome to The MongoDB Community Forums! :wave:

I saw that you haven’t had a response on this topic yet, were you able to find a solution for this error?
If not, then could you please provide a few additional details for me to understand your use-case better?

  • Could you clarify that you’re matching a billion ObjectId by putting them all into an array?
  • How big is your database?
  • MongoDB version being used
  • What are you trying to achieve/requirements?
  • More details regarding the query portion of your code snippet? (Redact any personal or sensitive information before posting here)
  • Check MongoDB logs for any errors that occur when you get this error at application end.

What is throwing this error? Could you post the whole error message, including lines before and after this error?

Regards,
Tarun