I want to get the nth position of a given collection.
However, all the slice methods I find, all refer to a given array in the document schema. In this case, I want to get the nth document of the collection. I tried $, but it gives me a syntax error:
result = await db.collection(col_name).find(
{ projection: { $: { $slice: [0, nPosition] } } }
).sort({ timestamp: -1 }).toArray();
Any clue how to do this?
>Solution :
use limit and skip :
result = await db.collection(col_name).find().sort({ timestamp: -1 }).skip(nPosition).limit(1).toArray();