How to save mongo shell output in text file

I’m new to mongodb and I have been used Mysql for teaching purpose only. While executing the sql command, i asked my student to store all the execution in single text file for further reference. Now, I’m connecting Atlas cluster via given link and didn’t install in my system. Then it is possible to store the mongo shell execution in text file? If so kindly help me to save it.


What exactly do you expect to store in the text file? Some writes’ dat is under local> if you run a replica set, some other stuff in the mongod log file but that’s more general information, etc.

For queries and their output, I don’t know of a simple way.

Hello @Santiago_Miranda
While executing the below commands in mango shell, it will generate the respective outputs side by side. Now I would like to save all that in a text / word file. I need the command to save that in a file.

MongoDB Enterprise atlas-7aawne-shard-0:PRIMARY> use sample_training
switched to db sample_training
MongoDB Enterprise atlas-7aawne-shard-0:PRIMARY> db.inspections.findOne();
“_id” : ObjectId(“56d61033a378eccde8a8354f”),
“id” : “10021-2015-ENFO”,
“certificate_number” : 9278806,
“business_name” : “ATLIXCO DELI GROCERY INC.”,
“date” : “Feb 20 2015”,
“result” : “No Violation Issued”,
“sector” : “Cigarette Retail Dealer - 127”,
“address” : {
“city” : “RIDGEWOOD”,
“zip” : 11385,
“street” : “MENAHAN ST”,
“number” : 1712

You may use

with –query to specify your query
and –out to specify the output file.

Thanks @steevej-1495 . Let me install it soon.