0

I want to get the count of all rows in a single collection into an output file. What is the correct way of doing this

Here is what I did but I am encountering an error.

mongoexport --host 10.1.0.1:27017 --db proddb --collection  UserColl --query "{db.getCollection('UserColl').count()}" --type=csv --out=output.csv
0

I created a sample.js file like the sample below:

db=db.getSiblingDB('DbName');

printjson( db.getCollection('CollectionName').find().count() );

then I run this script below on cmd:

mongo --host IP:PORT --username username --password password --authenticationDatabase admin --quiet sample.js > sample.csv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.