I am trying to paginate a nested document in a mongoDB collection.
This is a sample of what my data looks like. I added uid
field whose value is a mongo ObjectId
with the hope that it’s going to point me to the next object in the itemInfo
array.
const item = {
_id: ObjectID,
name: 'Test',
itemInfo : [
{
uid: "ObjectID",
itemData: [{}, {}]
},
{
uid: "ObjectID",
itemData: [{}, {}]
},
{
uid: "ObjectID",
itemData: [{}, {}]
},
{
uid: "ObjectID",
itemData: [{}, {}]
}
]
}
However, Running this query below returns the next root
objects in my database and not the next object in the itemInfo
array.
const pageSkin = await db
.find({ "itemInfo.uid": { $gt: new ObjectId("UidFromItemInfoArray") } })
.limit(pgLimit + 1)
How can i achieve my desired solution ?