当前位置:网站首页>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})
边栏推荐
- Oracle tablespace management
- [C language] merge sort
- Bzoj 3747 poi2015 kinoman segment tree
- [quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
- 零道云新UI设计中
- Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
- Reinforcement learning - learning notes 4 | actor critical
- Debezium series: idea integrates lexical and grammatical analysis ANTLR, and check the DDL, DML and other statements supported by debezium
- 期货如何网上开户?安不安全?
- What is PyC file
猜你喜欢
[quick start to digital IC Verification] 8. Typical circuits in digital ICs and their corresponding Verilog description methods
Wechat applet regular expression extraction link
Parler de threadlocal insecurerandom
.Net分布式事務及落地解决方案
Interviewer: what is the internal implementation of set data types in redis?
. Net distributed transaction and landing solution
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (半柔性对接 AutoDock)
Leetcode: binary tree 15 (find the value in the lower left corner of the tree)
无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...
Securerandom things | true and false random numbers
随机推荐
C language OJ gets PE, OJ of ACM introduction~
leetcode刷题:二叉树18(最大二叉树)
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
Android interview classic, 2022 Android interview written examination summary
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?
1:引文;
Leetcode(695)——岛屿的最大面积
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
Debezium series: PostgreSQL loads the correct last submission LSN from the offset
图嵌入Graph embedding学习笔记
leetcode刷题:二叉树16(路径总和)
Scala basics [HelloWorld code parsing, variables and identifiers]
Go language learning tutorial (16)
零道云新UI设计中
Fundamentals of deep learning convolutional neural network (CNN)
A solution to PHP's inability to convert strings into JSON
2022年7月4日-2022年7月10日(ue4视频教程mysql)
js方法传Long类型id值时会出现精确损失