Is this possible to write the query result to the file from mongo js script. I have searched a lot, but I didn\'t find any solution.
ex:-
cursor = db
Wouldn't it be simpler to use one of the Mongo drivers for a general purpose language (such as Python, Ruby, Java, etc) and write your results to a file that way, in a format you can use (such as CSV, etc.)?
UPDATE: According to the documentation for mongodump you can export a collection with a query:
$ ./mongodump --db blog --collection posts
-q '{"created_at" : { "$gte" : {"$date" : 1293868800000},
"$lt" : {"$date" : 1296460800000}
}
}'
However you would need to import that collection back into MongoDB to operate on it or use mongoexport to export as JSON or CSV using the same query flag (-q
) as mongodump
.