头歌 MongoDB 文档的高级查询操作(全部关卡)

第一关

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

版权声明:本文为博主作者:海浪~&原创文章,版权归属原作者,如果侵权,请联系我们删除!

原文链接:https://blog.csdn.net/weixin_61657766/article/details/127245419

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2024年4月22日
下一篇 2024年4月22日

相关推荐