MongoDB exports query results to file examples
- 2020-05-13 03:44:53
- OfStack
dump.js
var c = db.user.find({nick_name:{$exists:true,$ne:''}}).limit(100);
while(c.hasNext()) {
printjson(c.next());
}
mongo 192.168.2.201:41211/dc_user dump.js > feed.json
The specified data from the user table of the dc_user library is stored in feed.json as json.
Note: printjson outputs formatted json text to facilitate viewing the data, but you cannot import mongoimport, if you need to import printjson instead of printjsononeline.