mongo-shellmongosh

Mongo Shell prompts for "it" when I want all results


How can I run a query that I know will return a large dataset without having to type "it" to see all result and without modifying the query itself?

I want to redirect all output to a file, so I'm doing the following:

mongosh < my.query > my.result

The last line in the result file is 'Type "it" for more', so I'm clearly not getting all results.

The query is:

db.coll.find({device_type: "XYZ"},{_id: 1,expire_date:1});

When I add .toArray() to the query, the file ends with "... 36 more items ]"


Solution

  • I found that I can put this statement ahead of the query:

    DBQuery.shellBatchSize=1000;
    

    Then I know I'll get at least 1000 docs. Still not ideal, because I may not know how many docs are in the result set. But it's gotten me past my current issue.