0

Can somebody tell me please where is the problem in this simple aggregation command:

db.test.aggregate([
    {
         $group: {
             _id: "$type",
             numbers: { $sum: 1 }
         } 
    }
]).pretty()

Collection has about 2 millions of documents and everyone has type field. But the result returns only few of them as result + message "Type "it" for more" If I type "it" it returns next partial aggregation result till the end. But I want to have the whole aggregation in one result. What am I doing wrong? Thanks.

Čamo
  • 3,863
  • 13
  • 62
  • 114

1 Answers1

1

MongoDB won't return you whole bunch of data because it has built-in pagination.

In other case (2 mil of documents) would crash your server/computer as it runs out of memory.

But, if you'd like to get all bunch of data, it's better to store it with script.
You can write script with your programming language, request db, paginate through data and store in some variable.
Example

Grynets
  • 2,477
  • 1
  • 17
  • 41
  • There is no option to get one result? Why should I write a script to do this if Mongodb could do the same thing. I read somewhere about option to allow Mongodb to use disc instead of RAM. But cant remember the name. – Čamo Jan 11 '19 at 16:44
  • @Čamo there is one option, but it's not best practice. Try something like this: `DBQuery.shellBatchSize = 500`. You should write this in cli. But, again, not best practice. – Grynets Jan 11 '19 at 16:48
  • 1
    @Čamo oh, I've remembered one thing, try this `db.collection.find().toArray()`. In this case you receive array, but with whole data. – Grynets Jan 11 '19 at 16:49