Cursor pagination for nested fields in mongoDB using ObjectId

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 ?

@Imad_Bouteraa hello mate! Could you help me out on this please?

The find methods return root documents that satisfy the query. If you only want specific elements of an array you must use $filter inside a projection.