博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【MongoDB】The basic operation of Mongodb, Insert\Query\Delete\Update
阅读量:4169 次
发布时间:2019-05-26

本文共 1765 字,大约阅读时间需要 5 分钟。

1, Insert

MongoDB is database storing document object, the type of which is called Bson.(like JSON);

Example:  // document defination 

 

 

Now after using command[db.posts.insert(doc)], you will insert record successfully if seeing the 

The following picture.

 

2. Query 

One of the fundamental functions of MongoDB is to support query dynamically, which is the same as the troditional relational database, but more effiecieny than that. 

2.1 Query Expression Ojbects:

Query expression objects document is also a bson-structure document. For example, we could use the following the command to find all the record in the collections:

 

2.2 Query Item

In addition to Query expression object, Mongodb still support extra argument items. For example, you may only wanna return some certain fields. For example:

Example 1: return all the fields expect for tags;

 

Example 2: return dall fields expect for comments and tags=”albert”

 

Example 3: return the only field ’name’ and gender=’male’

3. Remove 

Removing operation is used to remove records from the collections.Example:

 

Advice: It’s better to use _id as condition when executing the remove operation/

Attention: In some conditions, when you are ready to remove one record, maybe in the meantime the update operation is updating this record which makes the reomve operation failed. As for this case, you could add the $atomic field to avoid this case. For example:

4. Update

4.1 Grammar 

Argument Description:

Criteria: the object used to set query conditions

Objnew: Object used to set update content. 

Upsert: if record exists, it will update it. Else insert a new record.

Multi: if multi matches conditoin, it will update all the records. 

 Attention: By fault, mongoDB will update the first record that matches the query condition.

 

 

 

 

你可能感兴趣的文章
Yocto tips (3): Yocto 如何重新编译Linux内核与dtb,并放到deploy目录?
查看>>
Yocto tips (4): Yocto 如何确定(找到)一个包的名字
查看>>
start kernel 之后没有任何输出与uboot无法将bootargs传入内核的调查方法与解决之道
查看>>
Yocto tips (5): Yocto如何更改source code的下载与git clone地址
查看>>
Yocto tips (7): Yocto Bitbake的clean与cleanall以及cleansstate的区别
查看>>
Yocto tips (19): Yocto SDK Toolchian的使用
查看>>
Yocto i.MX6 (TQIMX6) (04) : 使用mjpg-streamer做一个WebCam Server
查看>>
Nexus 7 Cyanogenmod OS Compile and errors
查看>>
Yocto tips (20): Yocto中qemu模拟器的使用,以zynq Cortex-A9为例
查看>>
打造嵌入式ARM Linux防火墙:1. iptables基础
查看>>
4G模块SIMCOM7100 LTE在ARM Linux下使用PPPD上网
查看>>
为小米4与小米3 Mi3 Mi4编译Cyanogenmod 12.1与13.0 (CM12与CM13) 的步骤以及错误解决
查看>>
原生Android系统的第一次开机google验证的解决
查看>>
S5P4418与S5P6618的Android boot.img的解压与压缩, Sparse ext4文件系统
查看>>
【EVB-335X-II试用体验】 u-boot与kernel的编译以及本地repo的建立
查看>>
【EVB-335X-II试用体验】 上手试用与资源使用
查看>>
【EVB-335X-II试用体验】 Yocto环境的建立及Rootfs的构建与使用
查看>>
<<C++程序设计原理与实践>>粗读--chapter0 chapter1 chapter2
查看>>
<<C++程序设计原理与实践>>粗读--chapter3 chapter4 Chapter5
查看>>
<<C++程序设计原理与实践>>粗读 -- chapter8 Chapter9
查看>>