Anyway to get first nth element in an array using sub document?

our data is bare number array, looks like:

[
1,
2,
3,
4
]

the length of array maybe 100000 long. But most time, we need only get top 20000.

So, is there some way to get top nth element from array?

Not currently - the sub-doc API only lets you access single paths (up to a maximum of ~16 IIRC) in a single request.

Having said that; storing 100,000 items in a single document probably isn’t the most efficient representation if you care about maximum performance. A rough estimate would be around ~500KB for the whole document - which you’d have to fetch the complete thing if you wanted a range of elements from it.

You might consider modifying your data model to split each logical item of data into multiple documents - say store chunks of 1,000 / 10,000 elements per document (so ~5KB per document); then if you want to get the top N you’d only need to fetch the chunks which mattered. However if you need atomic updates then that would introduce additional complexity.