当前位置:网站首页>mongodb $符号的神奇用法+mongo数据类型
mongodb $符号的神奇用法+mongo数据类型
2022-07-17 08:23:00 【General_zy】
$
“$” 在 update 中 加上关键字 就变成了修改器
其实 “$” 字符 独立出现也是有意义的 , 可以理解为一个代指符

现在把 “score”: 100 的 test_list 里面的 2 改为 9,
{$set :{“test_list.0” : 9}} 这样就是对应 Array 中的下标进行修改了 “test_list.下标”,
如果 是 一个很长很长很长的 Array 怎么整呢
$ 字符 在语句中代表了下标,位置,使用 update的话, 满足条件的数据下标位置就会传递到 $ 字符中。
$inc $set $unset $push $pull
- {$inc:{“score”:1}}的意思是,"score"的原有数值上面 +1
- $set略
- {$unset:{“english_name” : 1}} 就是删除 “english_name” 这个 field
- 在 Array(list) 的尾端加入一个新的元素 {“$push” : {“test_list” : 6}}
- $pull 就是指定删除Array中的某一个元素,只要满足条件,就会将Array中所有满足条件的数据全部清除掉
- {$pop:{“test_list” : -1}} -1 代表最前面, 1 代表最后边, $pop : 指定删除Array中的第一个 或 最后一个 元素
数据类型
Object ID :Documents 自生成的 _id
String: 字符串,必须是utf-8
Boolean:布尔值,true 或者false (Python中 True False 首字母大写)
Integer:整数
Double:浮点数(float64)
Arrays:数组或者列表
Object:字典
Null:空数据类型
Timestamp:时间戳
Date:存储当前日期或时间unix时间格式
ObjectId
“_id” : ObjectId(“5b151f8536409809ab2e6b26”)
- “5b151f85” 代指的是时间戳,这条数据的产生时间(0-8字节)
- “364098” 代指某台机器的机器码,存储这条数据时的机器编号(9-14字节的机器标识符)
- “09ab” 代指进程ID,多进程存储数据的时候,非常有用的(15-18字节的进程id)
- “2e6b26” 代指计数器,这里要注意的是,计数器的数字可能会出现重复,不是唯一的(19-24字节是计数器)
- 只要是支持MongoDB的语言,都会有一个或多个方法,对ObjectID进行转换
可以得到以上四种信息 - 这个类型是不可以被JSON序列化的
边栏推荐
猜你喜欢

Openfeign service interface call

Redis common data types - redis list and redis set

Xgen hair guide history cleared solution

Linear regression + basic optimization of deep learning

Microservices and microservice architecture

Gateway新一代网关

Ribbon load balancing service call

Picture browser

Use of OpenCV polar transformation function warppolar

Baidu Apollo
随机推荐
Introduction to deep learning exercises sorting in the first week of deep learning
Redis common data types - redis list and redis set
Consul服务注册与发现
Quanzhi v3s learning record (13) use of ov2640
CPU load of webgl - webgl comparison
石墨厚度测量
STM32CUBEIDE(9)----USART通过DMA收发
6-9 vulnerability exploitation telnet login rights lifting
【CTF】pwn2_sctf_2016
65. Restful specification
深度学习之线性回归+基础优化
OpenFeign服务接口调用
力扣912排序数组笔记
Redis6 new data type geospatial
Yyds dry inventory cross origin cross domain request
Database write Optimization: database and table segmentation and related issues
5.1 security vulnerabilities and Prevention
JS学习笔记04-05——构造函数的修改以及使用工厂方法创建
把HBuilderX的主题变成vscode
[leetcode] general operation summary