当前位置:网站首页>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})
边栏推荐
- leetcode刷题:二叉树13(相同的树)
- 浅浅的谈一下ThreadLocalInsecureRandom
- Cocos2d-x项目总结中的一些遇到的问题
- ACM getting started Day1
- Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
- Is it safe for Guosen Securities to open an account online?
- E. Singhal and Numbers(质因数分解)
- js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
- Debezium series: PostgreSQL loads the correct last submission LSN from the offset
- c——顺序结构
猜你喜欢

leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
![[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design](/img/92/7af0db21b3d7892bdc5dce50ca332e.png)
[quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design

Leetcode brush question: binary tree 14 (sum of left leaves)

.Net分布式事務及落地解决方案
![[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp](/img/32/738df44b6005fd84b4a9037464e61e.jpg)
[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp

- Oui. Net Distributed Transaction and Landing Solution

Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables

Solve the problem that the database configuration information under the ThinkPHP framework application directory is still connected by default after modification

Interviewer: what is the internal implementation of set data types in redis?

【数字IC验证快速入门】1、浅谈数字IC验证,了解专栏内容,明确学习目标
随机推荐
银河证券在网上开户安全吗?
How to retrieve the root password of MySQL if you forget it
leetcode刷题:二叉树18(最大二叉树)
Hong Kong stocks will welcome the "best ten yuan store". Can famous creative products break through through the IPO?
实操演示:产研团队如何高效构建需求工作流?
July 4, 2022 - July 10, 2022 (UE4 video tutorial MySQL)
Is it safe for Galaxy Securities to open an account online?
Debezium series: modify the source code to support UNIX_ timestamp() as DEFAULT value
[quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)
Guidelines for application of Shenzhen green and low carbon industry support plan in 2023
leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
95后阿里P7晒出工资单:狠补了这个,真香...
Unity编辑器扩展 UI控件篇
. Net distributed transaction and landing solution
What is PyC file
计算lnx的一种方式
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
How to safely and quickly migrate from CentOS to openeuler
leetcode刷题:二叉树15(找树左下角的值)
【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)