-1
user.aggregate([
  {
    $match: {
      age: { $gt: 18 },
      city: { $in: ["chicago", "paris"] }
    }
  },
  {
    $sort: {
      last_logged_in: -1
    }
  },
  {
    $limit: 10000
  }
])

If the user collection is partitioned into 10 shards, will each shard return 10,000 documents, totalling to 100,000?

1 Answers1

0

The answer is yes:

If the query limits the size of the result set using the limit() cursor method, the mongos instance passes that limit to the shards and then re-applies the limit to the result before returning the result to the client.

https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/#limits

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437