Step into MongoDB - 02 - 数据类型
来源:互联网 发布:移动协同办公软件 编辑:程序博客网 时间:2024/05/17 23:40
目录
- 数据类型
- 分类
- 数值类型
- Shell 中的数值
- 数组类型
- 访问数组中的元素
- 使用
- 数据类型
摘要
数值类型,访问数组
数据类型
分类
- null
- boolean
- 32bit int
- 64bit int
- 64bit float
- string
- ObjectId
- 等等
数值类型
MongoDB 支持 3 种类型:32 位整数,64 位整数和 64 位浮点数。
规律
- 默认有小数点的数字会被保存为 64 位 double。
- 在32位机器上
- 没有小数点的数字会被保存为 32 位 int,使用 bigint 会被保存为 64 位 int
- 超过 64 位 int 的数字会被自动解析为 double
- 在 64 位机器上
- 没有小数点的数字会被保存为 64 位 int,且无法保存 32 位 int
所以如果 32 位机器和 64 位机器共同使用的话,会发生各种奇怪的现象。
Shell 中的数值
Shell 只有一种数字类型 8-byte float
,这意味着它并不是总能显示正确的 8-byte integer。在 shell 显示 64 位 int 时,它可能会被显示为近似值。
例如:
{ "x":{ "floatApprox":xxx, "top":yyy, "bottom":zzz }}
这并不表示 x 是浮点型,而是表示 x 并不精确,top 是高 32 位,bottom 是低 32 位
但是 Javascript shell 只支持 64 位浮点数,这意味着即使从数据库原封不动取得一个 32 位整数的记录再重新更新,数据也会被转换为 64 位浮点数。
数组类型
访问数组中的元素
db.<dbName>.<collectionName>.<index>
例:
db.blog.find({ "comments.0.author" : "Jane" })
使用 “$”
很多时候必须先进行查询才能获得下标。此时可以使用 $
,其总会返回匹配条件的第一条。
<collectionName>.$
例:
db.blog.update({ "comments.author" : "John"}, {"$set" : {"comments.$.author" : "Jim"}})`
0 0
- Step into MongoDB - 02 - 数据类型
- Step into Scala - 02 - 数据类型
- Step into Kotlin - 02 - 数据类型
- Step into MongoDB - 09 - 索引
- Step into MongoDB - 11 - MapReduce
- Step into MongoDB - 14 - 分片
- Step into MongoDB - 15 - GridFS
- Step into MongoDB - 01 - 安装与运行
- Step into MongoDB - 03 - Database & Collection & Document
- Step into MongoDB - 04 - 简单查询
- Step into MongoDB - 05 - 插入与删除
- Step into MongoDB - 06 - 更新操作
- Step into MongoDB - 07 - 复杂查询
- Step into MongoDB - 08 - 聚合查询
- Step into MongoDB - 10 - 服务端命令
- Step into MongoDB - 12 - 主从复制
- Step into MongoDB - 13 - 副本集
- Step into MongoDB - 16 - 账号管理
- LoadRunner中进程运行和线程运行区别
- 几道基本的java和Android面试题
- 作业3.22
- unity5 和UGUI的小Demo贪吃蛇
- poj 1080-Human Gene Functions
- Step into MongoDB - 02 - 数据类型
- 1
- meteor安装
- java+mysql 中文乱码问题解决
- 大O表示法
- Java 学习博客笔记
- SQL语句select随机调取10行数据 Access/SQL Server/Mysql等数据库
- Unity3D之Position的设置
- OSPF建立邻居的条件