当前位置:网站首页>Mongodb/ document operation
Mongodb/ document operation
2022-07-05 20:17:00 【Why not sell egg cakes well】
06 Inserted into the document
Insert multiple
db.stus.insert({ object 2},{ object 3});
Will be generated according to the timestamp id
You can also define
Import the development environment data into the production environment
Data may be duplicated Add to each document id attribute , Make sure it's unique .
7 Query the document
db.status.find({
_id:"hello"});
Query all eligible documents ;
db.stus.find({
age:16,name:"xians"});
There are many ways of conditional transmission .
;
db.collection.findOne(); // Query the first eligible document
find() It returns an array ;
db.collection.find({
}).count();// Query the number of all results
8 Modify the document
db.stus.update({name:" The sand monk "},{age:33});
Partial modification
db.stus.update(
{
"_id":ObjectId("hsfhkdh")},
{
$set:{
name:" Pig eight quit ",
address:" Liusha River "
}}
)
$unset
db.stus.update(
{"_id":ObjectId("hsfhkdh")},
{$unset:{
name:" Pig eight quit "
}}
)
db.collection.updateMany() // Modify multiple qualified documents at the same time .
db.collection.updateOne() // Modify a qualified document
update // Only one is changed by default
modify update The default attribute of can be modified at the same time
db.stus.update(
{"name":" solve "}
{$set:{
name:" Pig eight quit "
}},
{multi:true}
)
9 Delete the document
remove Delete multiple by default , Delete only one , You need to set the parameter to true;
db.stus.remove({_id:"hello"},true);
// If you pass an empty parameter , Delete all
// Empty the set , Slightly poor performance . First match , And then delete . It is more convenient to delete the set directly
db.stus.remove({});
Delete the collection
db.stus.drop();
Generally, database data will not be deleted , Just add a parameter , To indicate whether the data has been deleted ,.
db.updateOne({name="ts"},{$set:{idDel:1}});
db.stus.find({idDel:0})
边栏推荐
- BZOJ 3747 POI2015 Kinoman 段树
- 【愚公系列】2022年7月 Go教学课程 004-Go代码注释
- 【c语言】归并排序
- Leetcode: binary tree 15 (find the value in the lower left corner of the tree)
- Go language | 03 array, pointer, slice usage
- 淺淺的談一下ThreadLocalInsecureRandom
- sun. misc. Base64encoder error reporting solution [easy to understand]
- Is it safe for Guosen Securities to open an account online?
- Debezium series: parsing the default value character set
- Guidelines for application of Shenzhen green and low carbon industry support plan in 2023
猜你喜欢
随机推荐
Schema和Model
.Net分布式事务及落地解决方案
mongodb文档间关系
document方法
ROS2专题【01】:win10上安装ROS2
CTF逆向基础
July 4, 2022 - July 10, 2022 (UE4 video tutorial MySQL)
leetcode刷题:二叉树10(完全二叉树的节点个数)
解决php无法将string转换为json的办法
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
C langue OJ obtenir PE, ACM démarrer OJ
基础篇——配置文件解析
Leetcode brush question: binary tree 14 (sum of left leaves)
【c语言】快速排序的三种实现以及优化细节
Ffplay document [easy to understand]
1:引文;
Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
信息学奥赛一本通 1339:【例3-4】求后序遍历 | 洛谷 P1827 [USACO3.4] 美国血统 American Heritage
炒股开户最低佣金,低佣金开户去哪里手机上开户安全吗