0

Let say I have a java script file "mongo.js" where i print some data from mongoDb to the shell console.It's possible to save that output to a txt file? The js file content:

db = connect("localhost:27017/test");
var cursor=db.test.find();
cursor.forEach(
   function(doc){
       print(doc.name);
   }
);

This is how I execute the file in mongo shell

load("mongo.js")

How to redirect the javascript output to a file? Tried so far:

mongo.exe --quiet mongo.js > file.txt
mongo.js > file.txt
  • 1
    Possible duplicate of [Printing Mongo query output to a file while in the mongo shell](http://stackoverflow.com/questions/22565231/printing-mongo-query-output-to-a-file-while-in-the-mongo-shell) – Sarath Nair Dec 08 '15 at 12:39

1 Answers1

0

Found a way to do it from terminal:

mongo mongo.js > "path to file"