mongo localhost:11111/test -u *** -p **** --quiet --eval "db.collections1.find({image_url: { $regex: '43.12'}}, {image_url: 1, id: 1}).sort({id: -1}).forEach(printjson);" > 1.txt
第二种方式:
先写个js文件myjsfile.js
cursor = db.collections1.find({image_url: { $regex: '43.12'}}, {image_url: 1, id: 1}).sort({id: -1}) while ( cursor.hasNext() ) { printjson( cursor.next() ); } //print(12)
然后执行下这个js文件
mongo localhost:11111/test -u *** -p **** myjsfile.js > 1.txt
参考官方文档:
http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/#mongo-shell-new-connections
花下眠工作室: http://huaxiamian.cc