2

I have 24 documents with the same user ID, when I want to match it all, mongo aggregation returns me only 20 elements but must return all 24. Is it limited by mongo or am I doing something wrong?

invzbl3
  • 5,872
  • 9
  • 36
  • 76

2 Answers2

1

Cursor Behavior

Mongo shell automatically iterates the cursor up to 20 times, as mentioned documentation.

But you can use the DBQuery.shellBatchSize to change the number of iteration from the default value 20. See Working with the mongo Shell for more information.

P.s. Yes, Compass has limited number of documents for aggregation by design.


MongoDB Compass 1.14.0:

the Preview of Documents in the Collection section of the Aggregations view displays 20 documents sampled from the current collection.


Additional links:

https://docs.mongodb.com/manual/tutorial/iterate-a-cursor/ https://docs.mongodb.com/manual/mongo/#format-printed-results https://docs.mongodb.com/manual/reference/method/db.collection.aggregate/#specify-an-initial-batch-size https://docs.mongodb.com/compass/master/aggregation-pipeline-builder/#aggregation-pipeline-builder How to print out more than 20 items (documents) in MongoDB's shell?

invzbl3
  • 5,872
  • 9
  • 36
  • 76
  • I set it in .mongorc.js, but it works only on mongoShell, it doesn't work in MongoCompass and in my aggregation. – Taras Danylchenko Jan 28 '19 at 12:07
  • @ТарасДанальченко did you try [to specify a query filter](https://stackoverflow.com/a/48445906/8370915) using MongoDB Compass? – invzbl3 Jan 28 '19 at 12:12
  • mmmm,I said about aggregation, not about the filter – Taras Danylchenko Jan 28 '19 at 12:17
  • @ТарасДанальченко Sorry, I'll check it. But as I see from the section [Aggregation Pipeline Builder](https://docs.mongodb.com/compass/master/aggregation-pipeline-builder/#aggregation-pipeline-builder) in Compass version 1.14.0, you can display just 20 by design. – invzbl3 Jan 28 '19 at 13:07
1

Step 1. Click on the setting icon on the top right corner :

Step 1

Step 2. Change the "Number of Preview Documents" as per requirement :

Step 2

Nikhil Londhe
  • 41
  • 2
  • 6