第一关
mongoimport -d mydb1 -c test --type csv --headerline --ignoreBlanks --file /home/example/student.csv
mongoexport -d mydb1 -c test -o /home/test1.json --type json
mongoexport -d mydb1 -c test -o /home/test1.csv --type csv -f "_id,name,age,sex,major"
第二关
命令行
mongoimport -d mydb2 -c test --type json --file /home/example/person.json
代码文件
echo "
db.test.find({hobbies:{\$all:['唱歌','跳舞']}}).sort({_id:1});
db.test.find({hobbies:{\$all:['羽毛球','跳舞']}}).sort({_id:1});
db.test.find({hobbies:{\$size:3}}).sort({_id:1});
db.test.find({hobbies:{\$exists:true}}).sort({_id:1});
db.test.find({age:{\$in:[19,23]}}).sort({_id:1});
db.test.find({age:{\$nin:[20]}}).sort({_id:1});
db.test.find({age:{\$mod:[9,2]}}).sort({_id:1});
"
第三关
代码文件
echo "
db.test.find({\$and:[{age:20},{sex:'男'}]}).sort({_id:1});
db.test.find({\$or:[{sex:'男'},{age:20}]}).sort({_id:1});
db.test.find({name:/^韩.*/}).sort({_id:1});
db.test.find({\$and:[{age:{\$gte:19}},{age:{\$lt:22}}]}).sort({_id:1});
db.test.find({\$or:[{age:{\$lt:19}},{age:{\$gt:21}}]}).sort({_id:1});
db.test.find({name:{\$not:/^韩.*/}}).sort({_id:1});
db.test.find({name:{\$not:/^韩.*/}}).count();
db.test.find({\$and:[{age:{\$gte:19}},{age:{\$lt:22}}]}).count();
"
命令行
mongoimport -d mydb3 -c test --type json --file /home/example/person.json
第四关
命令行
mongo
use mydb4
for(var i=0;i<10000;i++)db.test.insert({_id:i,title:"MongoDB"+i,content:"hello"+i});
exit
mongoexport -d mydb4 -c test -f _id.title,content -o /home/test/test4.csv --type csv