当前位置:网站首页>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})
边栏推荐
- USACO3.4 “破锣摇滚”乐队 Raucous Rockers - DP
- JVMRandom不可设置种子|问题追溯|源码追溯
- Autumn byte interviewer asked you any questions? In fact, you have stepped on thunder
- JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
- 【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
- Database logic processing function
- How to select the Block Editor? Impression notes verse, notation, flowus
- 挖财钱堂教育靠谱安全吗?
- How to safely and quickly migrate from CentOS to openeuler
- Leetcode(695)——岛屿的最大面积
猜你喜欢

About the priority of Bram IP reset
![[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)](/img/6d/110b87747f0a4be52da9fd49a05b82.png)
[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)

Database logic processing function

Fundamentals of deep learning convolutional neural network (CNN)

关于BRAM IP复位的优先级

Leetcode: binary tree 15 (find the value in the lower left corner of the tree)

淺淺的談一下ThreadLocalInsecureRandom

深度學習 卷積神經網絡(CNN)基礎

基础篇——配置文件解析

leetcode刷题:二叉树13(相同的树)
随机推荐
Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
微信小程序正则表达式提取链接
Guidelines for application of Shenzhen green and low carbon industry support plan in 2023
信息学奥赛一本通 1337:【例3-2】单词查找树 | 洛谷 P5755 [NOI2000] 单词查找树
C langue OJ obtenir PE, ACM démarrer OJ
Autumn byte interviewer asked you any questions? In fact, you have stepped on thunder
Ffplay document [easy to understand]
Scala基础【HelloWorld代码解析,变量和标识符】
图嵌入Graph embedding学习笔记
Base du réseau neuronal de convolution d'apprentissage profond (CNN)
leetcode刷题:二叉树13(相同的树)
y57.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(三十)
What is PyC file
Go language learning tutorial (16)
leetcode刷题:二叉树10(完全二叉树的节点个数)
Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
Wechat applet regular expression extraction link
Analysis of openh264 decoded data flow