I have a collection called Messages
which looks like this
{
_id: "6106b76f07e61c072c3587ad",
content: "this is an example content",
}
Suppose I have around 1000 items in this collection, and I want to query documents in batches of 10, based on the _id
that I will provide i.e., 10 items after a particular _id
Consider this collection as shown,
[
{
_id: "1",
content: "this is an example content",
},
{
_id: "2",
content: "this is an example content",
},
{
_id: "3",
content: "this is an example content",
},
{
_id: "4",
content: "this is an example content",
},
{
_id: "5",
content: "this is an example content",
},
{
_id: "6",
content: "this is an example content",
},
.
.
... 1000 such items
]
What I want is to query these documents based on the last _id that I send.
Example
Initially, LastID = null
For _id = null
, Send 1st 10
items
Now LastID
becomes 10
(or whatever _id the last element has)
For _id = 10
, Send 10 documents after _id = 10