mongodb增删改查
2021/8/6 19:06:13
本文主要是介绍mongodb增删改查,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
insert
insert
db.users.insert([{"name":"张三","age":18,"status":1},{"name":"李四","age":20,"status":0}]);
insertOne
db.users.insertOne({"name":"王五","age":22,"status":1});
insertMany
db.users.insertMany([{"name":"李六","age":24,"status":1},{"name":"陈真","age":27,"status":1}]);
find
db.users.findOne({});
查全部
db.schools.find({});
in查询
db.users.find({"age":{$in:[18,20]}});
and查询
db.users.find({"age":22,"status":1});
or查询
db.users.find({$or:[{"name":"李四"},{"age":27}]});
and,or
db.users.find({"status":1,$or:[{"name":"王五"},{"age":27}]});
update
updateOne
db.users.updateOne({"name":"张三"},{$set:{"age":20}});
updateMany
db.users.updateMany({"age":20},{$set:{"age":25},$currentDate:{lastModified:true}});
update
db.users.update({"status":1},{$set:{"age":21}},{multi:true});
delete
deleteOne
db.users.deleteOne({"name":"陈真"});
deleteMany
db.users.deleteMany({"name":{$in:["王五","张三"]}});
remove
db.users.remove({"status":1},{justOne:true});
db.users.remove({"status":1});
这篇关于mongodb增删改查的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-12Cargo deny安装指路
- 2024-11-02MongoDB项目实战:从入门到初级应用
- 2024-11-01随时随地一键转录,Google Cloud 新模型 Chirp 2 让语音识别更上一层楼
- 2024-10-25Google Cloud动手实验详解:如何在Cloud Run上开发无服务器应用
- 2024-10-24AI ?先驱齐聚 BAAI 2024,发布大规模语言、多模态、具身、生物计算以及 FlagOpen 2.0 等 AI 模型创新成果。
- 2024-10-20goland工具下,如修改一个项目的标准库SDK的版本-icode9专业技术文章分享
- 2024-10-17Go学习:初学者的简单教程
- 2024-10-17Go学习:新手入门完全指南
- 2024-10-17Golang学习:初学者入门教程
- 2024-10-17Golang学习:新手入门教程