IXSCAN with LIMIT returns unexpected result

Hello there.

I’m using MongoDB 4.4 version and i have some questions with executionStats result.


  feature: { $in: [ "buy", "sell", "ship", "contact" ] },
  date_time: { $gt: new ISODate(~~) },
  _id: { $gt: ObjectId(~~) }
.sort({ date_time: 1 })
.limit(limit size)


  • id
  • feature_1_date_time_1

IXSCAN (multiple stages) → SORT_MERGE → FETCH (nReturned limit_size) → LIMIT (nReturned limit_size)
(not real plan)

First - I expect my query scans always same number of index keys but with limits, there are difference with scanned index keys in IXSCAN stage. Are limit aggregation affects to ixscan stage?

Second - In executionStats result, FETCH stage filters _id field so i expect filtering works in this stage. But when i change comparision value of _id field in query, IXSCAN and SORT_MERGE stages has different nReturned value with previous _id value.
It doesn’t occurs when i don’t use limit operation. Why?

Third - FETCH nReturned and LIMIT nReturned is same. I expected that FETCH returns more that limit_size and LIMIT returns exactly limit_size docs but it seems that it’s already applied in FETCH stage.
Did i missed something about how index works?

Thanks for reading.