I am 1 day old to MongoDB so bear with me. I am simply trying to output a simple query to a *.json file. The query is:
db.collection.findOne()
// collection is substituted with the correct collection name, the query preludes 'use db' command where db is substituted with correct db name
Then, in reference to this article and a bunch of other SO answers, I perform the following query:
--eval "printjson(db.results.findOne())" >> sample.json
I even created a blank sample.json file, and I experimented --eval with -eval etc. I keep getting:
SyntaxError: missing ;before statement (shell):1
I add semi colons at arbitrary places, but I have no idea why this doesn't work for me.
Can anybody point out what I am missing here?
Complete sequence of commands:
mongo
use dbname
--eval "printjson(db.collectionName.findOne())" >> sample.json
P.S: The command db.collectionName.findOne() does give me an output
--eval should be passed as an argument to "mongo" command. I tried below and it worked: