Sort in descending order results in field omitted from final document

This is a sample chat document in my collection. I’ve an index on participants field and another index on timestamp. Both indexes are in ascending order.

  "_id": { "$oid": "1fe49b6b1bf5fe3898cceac7" },
  "participants": ["bdf8bbcdbaf1bcb0fad67bfd","42a907e5cd50bf52ee7aafbb"],
  "seen": false,
  "lastMsg": "Lorem Ipsum",
  "timestamp": {"$date": "2022-01-06T06:00:00.000Z"}

When I run $sort in pipeline based on timestamp : -1, lastMsg field is not included in the results. But when I add timestamp:1, I get the lastMsg field

EDIT=> My bad, mock data didn’t have lastMsg in some docs. Can’t delete the post.

No need to delete the post. It is good for people to step away from assumptions and check the actual data.

Thanks for your update.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.