Tag Archives: mongoexport

How to Export Mongo collection without mongoexport command

As we know we can export mongo collection or mutliple collections using mongoexport command
but sometime you don’t have access for mongoexport command for given user.
So you can export mongo collection without using mongoexport command as below.
1. Rurn following command in shell

mongo | tee collection.json

2. And then run following command

db.collection.find({}).forEach(function(f){print(tojson(f,'',true))})

3. Now open file collection.json file and remove extra lines from file(like use db statements etc or command itself)
from start and end of file