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?
-
1Are you trying on mongo prompt? if yes, then it will by default show 20 records. To see more, you can type `it` which will show you next 20.. – Ravi Kumar Gupta Jan 28 '19 at 10:51
-
Please mention the tool you're using to run the aggregation query – Andrew Nessin Jan 28 '19 at 12:03
2 Answers
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.
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?

- 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
-
-
@ТарасДанальченко 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
Step 1. Click on the setting icon on the top right corner :
Step 2. Change the "Number of Preview Documents" as per requirement :

- 41
- 2
- 6