当前位置:网站首页>mongodb/文档操作
mongodb/文档操作
2022-07-05 20:11:00 【为什么不好好卖蛋饼】
06 插入文档
插入多个
db.stus.insert({对象2},{对象3});
会根据时间戳生成id
也可以自己定义
开发环境数据导入到生产环境
数据可能有重复 给每个文档添加id属性,确保唯一性。
7 查询文档
db.status.find({
_id:"hello"});
查询所有符合条件的文档;
db.stus.find({
age:16,name:"xians"});
条件传递方式有很多种。
;
db.collection.findOne(); //查询符合条件的第一个文档
find() 返回的是一个数组;
db.collection.find({
}).count();//查询所有结果的数量
8 修改文档
db.stus.update({name:"沙和尚"},{age:33});
局部修改
db.stus.update(
{
"_id":ObjectId("hsfhkdh")},
{
$set:{
name:"猪八戒",
address:"流沙河"
}}
)
$unset
db.stus.update(
{"_id":ObjectId("hsfhkdh")},
{$unset:{
name:"猪八戒"
}}
)
db.collection.updateMany() //同时修改多个符合条件的文档。
db.collection.updateOne() //修改一个符合条件的文档
update //默认只改一个
修改update的默认属性达到可以同时修改多个的目的
db.stus.update(
{"name":"解决"}
{$set:{
name:"猪八戒"
}},
{multi:true}
)
9 删除文档
remove默认删除多个,仅仅删除一个,需要设置参数为true;
db.stus.remove({_id:"hello"},true);
//如果传一个空参,删除全部
//清空集合,性能略差。先匹配,再删除。更方便方法直接删除集合
db.stus.remove({});
删除集合
db.stus.drop();
一般数据库数据都不会删除,只是去添加一个参数,来表示数据是否被删除,。
db.updateOne({name="ts"},{$set:{idDel:1}});
db.stus.find({idDel:0})
边栏推荐
- Unity编辑器扩展 UI控件篇
- Is the education of caiqiantang reliable and safe?
- ICTCLAS word Lucene 4.9 binding
- Build your own website (16)
- A way to calculate LNX
- Reinforcement learning - learning notes 4 | actor critical
- Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
- leetcode刷题:二叉树10(完全二叉树的节点个数)
- [C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp
- 618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?
猜你喜欢
14. Users, groups, and permissions (14)
Go language | 02 for loop and the use of common functions
【数字IC验证快速入门】3、数字IC设计全流程介绍
Oracle tablespace management
leetcode刷题:二叉树13(相同的树)
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
Leetcode brush question: binary tree 14 (sum of left leaves)
基础篇——配置文件解析
A solution to PHP's inability to convert strings into JSON
随机推荐
Reinforcement learning - learning notes 4 | actor critical
.Net分布式事務及落地解决方案
Is it safe for CICC fortune to open an account online?
618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?
c語言oj得pe,ACM入門之OJ~
About the priority of Bram IP reset
C language OJ gets PE, OJ of ACM introduction~
Leetcode: binary tree 15 (find the value in the lower left corner of the tree)
1: Citation;
Debezium series: idea integrates lexical and grammatical analysis ANTLR, and check the DDL, DML and other statements supported by debezium
【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
Go language | 03 array, pointer, slice usage
2022年7月4日-2022年7月10日(ue4视频教程mysql)
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
零道云新UI设计中
【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
Leetcode(347)——前 K 个高频元素
Based on vs2017 and cmake GUI configuration, zxing and opencv are used in win10 x64 environment, and simple detection of data matrix code is realized
How to select the Block Editor? Impression notes verse, notation, flowus
leetcode刷题:二叉树16(路径总和)