- MongoDB官方文档中文版
- MongoDB中文手册说明
- MongoDB简介
- 安装 MongoDB
- The mongo Shell
- MongoDB CRUD 操作
- 聚合
- 数据模型
- 事务
- 索引
- 安全
- 安全检查列表
- 启用访问控制
- 身份验证
- 基于角色的访问控制
- TLS / SSL(传输加密)
- 静态加密
- 客户端字段级加密
- 审计
- 网络和配置强化
- 实现字段级别修订
- 安全参考
- 附录
- 变更流
- 复制
- 分片
- 分片键
- 哈希分片
- 范围分片
- 区
- 管理分片区
- 按位置细分数据
- 用于更改SLA或SLO的分层硬件
- 按应用或客户细分数据
- 仅插入工作负载的分布式本地写入
- 管理分片区
- 使用块进行数据分区
- 在分片集群中拆分数据块
- 管理
- 存储
- 存储引擎
- 日志记录
- 管理日志记录
- GridFS
- FAQ:MongoDB 存储
- 存储引擎
- 参考
- 运算符
- 查询与映射运算符
- 更新运算符
- 聚合管道阶段
- 聚合管道操作符
- $abs (aggregation)
- $acos (aggregation)
- $acosh (aggregation)
- $add (aggregation)
- $addToSet (aggregation)
- $allElementsTrue (aggregation)
- $and (aggregation)
- $anyElementTrue (aggregation)
- $arrayElemAt (aggregation)
- $arrayToObject (aggregation)
- $asin (aggregation)
- $asinh (aggregation)
- $atan (aggregation)
- $atan2 (aggregation)
- $atanh (aggregation)
- $avg (aggregation)
- $ceil (aggregation)
- $cmp (aggregation)
- $concat (aggregation)
- $concatArrays (aggregation)
- $cond (aggregation)
- $convert (aggregation)
- $cos (aggregation)
- $dateFromParts (aggregation)
- $dateToParts (aggregation)
- $dateFromString (aggregation)
- $literal (aggregation)
- 查询修饰符
- 数据库命令
- 聚合命令
- 地理空间命令
- 查询和写操作命令
- 查询计划缓存命令
- 认证命令
- 用户管理命令
- 角色管理命令
- 复制命令
- 分片命令
- 会话命令
- 管理命令
- 诊断命令
- 免费监控命令
- 系统事件审计命令
- mongo Shell 方法
- 集合方法
- db.collection.aggregate()
- db.collection.bulkWrite()
- db.collection.copyTo()
- db.collection.count()
- db.collection.countDocuments()
- db.collection.estimatedDocumentCount()
- db.collection.createIndex()
- db.collection.createIndexes()
- db.collection.dataSize()
- db.collection.deleteOne()
- db.collection.deleteMany()
- db.collection.distinct()
- db.collection.drop()
- db.collection.dropIndex()
- db.collection.dropIndexes()
- db.collection.ensureIndex()
- db.collection.explain()
- db.collection.find()
- db.collection.findAndModify()
- db.collection.findOne()
- db.collection.findOneAndDelete()
- db.collection.findOneAndReplace()
- db.collection.findOneAndUpdate()
- db.collection.getIndexes()
- db.collection.getShardDistribution()
- db.collection.getShardVersion()
- db.collection.insert()
- db.collection.insertOne()
- db.collection.insertMany()
- db.collection.isCapped()
- db.collection.latencyStats()
- db.collection.mapReduce()
- db.collection.reIndex()
- db.collection.remove()
- db.collection.renameCollection()
- db.collection.replaceOne()
- db.collection.save()
- db.collection.stats()
- db.collection.storageSize()
- db.collection.totalIndexSize()
- db.collection.totalSize()
- db.collection.update()
- db.collection.updateOne()
- db.collection.updateMany()
- db.collection.watch()
- db.collection.validate()
- 词汇表
- 默认的MongoDB端口
- 默认的MongoDB读/写关注
- 服务器会话
- MongoDB驱动
- FAQ
- 联系我们
- 更多资料
- [快学Mongo]
- [Mongo问题讨论区]
- [Mongo 驱动使用手册]
- 本书使用 GitBook 发布
MongoDB Extended JSON (v2)
MongoDB Extended JSON
On this page
JSONcan only represent a subset of the types supported byBSON. To preserve type information, MongoDB adds the following extensions to the JSON format:
- Strict mode . Strict mode representations of BSON types conform to the JSON RFC . Any JSON parser can parse these strict mode representations as key/value pairs; however, only the MongoDB internal JSON parser recognizes the type information conveyed by the format.
mongo
Shell mode . The MongoDB internal JSON parser and themongo
shell can parse this mode.
The representation used for the various data types depends on the context in which the JSON is parsed.
Parsers and Supported Format
Input in Strict Mode
The following can parse representations in strict mode_with_recognition of the type information.
- REST Interfaces
mongoimport
--query
option of various MongoDB tools- MongoDB Compass
Other JSON parsers, includingmongo
shell anddb.eval()
, can parse strict mode representations as key/value pairs, but_without_recognition of the type information.
Input inmongo
Shell Mode
The following can parse representations inmongo
shell mode_with_recognition of the type information.
- REST Interfaces
mongoimport
--query
option of various MongoDB toolsmongo
shell
Output in Strict mode
mongoexport
andREST and HTTP Interfacesoutput data inStrict mode.
Output inmongo
Shell Mode
bsondump
outputs inmongo
Shell mode.
BSON Data Types and Associated Representations
The following presents the BSON data types and the associated representations inStrict mode_andmongo
_Shell mode.
Binary
data_binary
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$binary": "<bindata>", "$type": "<t>" } | BinData ( <t>, <bindata> ) |
is the base64 representation of a binary string.
is a representation of a single byte indicating the data type. In Strict mode it is a hexadecimal string, and in Shell mode it is an integer. See the extended bson documentation. http://bsonspec.org/spec.html
Date
data_date
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$date": "<date>" } | new Date ( <date> ) |
InStrict mode,
is an ISO-8601 date format with a mandatory time zone field following the templateYYYY-MM-DDTHH:mm:ss.mmm<+/-Offset>
.
The MongoDB JSON parser currently does not support loading ISO-8601 strings representing dates prior to theUnix epoch. When formatting pre-epoch dates and dates past what your system’stime_t
type can hold, the following format is used:
{ "$date" : { "$numberLong" : "
<
dateAsMilliseconds
>
" } }
InShell mode,
is the JSON representation of a 64-bit signed integer giving the number of milliseconds since epoch UTC.
Timestamp
data_timestamp
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$timestamp": { "t": <t>, "i": <i> } } | Timestamp( <t>, <i> ) |
<
t
>
is the JSON representation of a 32-bit unsigned integer for seconds since epoch.<
i
>
is a 32-bit unsigned integer for the increment.
Regular Expression
data_regex
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$regex": "<sRegex>", "$options": "<sOptions>" } | /<jRegex>/<jOptions> |
<
sRegex
>
is a string of valid JSON characters.<
jRegex
>
is a string that may contain valid JSON characters and unescaped double quote ("
) characters, but may not contain unescaped forward slash (/
) characters.<
sOptions
>
is a string containing the regex options represented by the letters of the alphabet.<
jOptions
>
is a string that may contain only the characters ‘g’, ‘i’, ‘m’ and ‘s’ (added in v1.9). Because theJavaScript
andmongo
Shell
representations support a limited range of options, any nonconforming options will be dropped when converting to this representation.
OID
data_oid
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$oid": "<id>" } | ObjectId( "<id>" ) |
is a 24-character hexadecimal string.
DB Reference
data_ref
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$ref": "<name>", "$id": "<id>" } | DBRef("<name>", "<id>") |
<
name
>
is a string of valid JSON characters.<
id
>
is any valid extended JSON type.
Undefined Type
data_undefined
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$undefined": true } | undefined |
The representation for the JavaScript/BSON undefined type.
You_cannot_useundefined
in query documents. Consider the following document inserted into thepeople
collection:
db.people.insert( { name : "Sally", age : undefined } )
The following queries return an error:
db.people.find( { age : undefined } )
db.people.find( { age : { $gte : undefined } } )
However, you can query for undefined values using$type
, as in:
db.people.find( { age : { $type : 6 } } )
This query returns all documents for which theage
field has valueundefined
.
MinKey
data_minkey
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$minKey": 1 } | MinKey |
The representation of the MinKey BSON data type that compares lower than all other types. SeeComparison/Sort Orderfor more information on comparison order for BSON types.
MaxKey
data_maxkey
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$maxKey": 1 } | MaxKey |
The representation of the MaxKey BSON data type that compares higher than all other types. SeeComparison/Sort Orderfor more information on comparison order for BSON types.
NumberLong
New in version 2.6.
data_numberlong
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$numberLong": "<number>" } | NumberLong( "<number>" ) |
NumberLong
is a 64 bit signed integer. You must include quotation marks or it will be interpreted as a floating point number, resulting in a loss of accuracy.
For example, the following commands insert9223372036854775807
as aNumberLong
with and without quotation marks around the integer value:
db.json.insert( { longQuoted : NumberLong("9223372036854775807") } )
db.json.insert( { longUnQuoted : NumberLong(9223372036854775807) } )
When you retrieve the documents, the value oflongUnQuoted
has changed, whilelongQuoted
retains its accuracy:
db.json.find()
{ "_id" : ObjectId("54ee1f2d33335326d70987df"), "longQuoted" : NumberLong("9223372036854775807") }
{ "_id" : ObjectId("54ee1f7433335326d70987e0"), "longUnQuoted" : NumberLong("-9223372036854775808") }
NumberDecimal
New in version 3.4.
data_numberdecimal
Strict Mode | mongo | Shell Mode |
---|---|---|
{ "$numberDecimal": "<number>" } | NumberDecimal( "<number>" ) |
NumberDecimal
is ahigh-precision decimal. You must include quotation marks, or the input number will be treated as a double, resulting in data loss.
For example, the following commands insert123.40
as aNumberDecimal
with and without quotation marks around the value:
db.json.insert( { decimalQuoted : NumberDecimal("123.40") } )
db.json.insert( { decimalUnQuoted : NumberDecimal(123.40) } )
When you retrieve the documents, the value ofdecimalUnQuoted
has changed, whiledecimalQuoted
retains its specified precision:
db.json.find()
{ "_id" : ObjectId("596f88b7b613bb04f80a1ea9"), "decimalQuoted" : NumberDecimal("123.40") }
{ "_id" : ObjectId("596f88c9b613bb04f80a1eaa"), "decimalUnQuoted" : NumberDecimal("123.400000000000") }
Copyright © 上海锦木信息技术有限公司 all right reserved,由 MongoDB汉化小组 提供技术支持文件修订时间: 2020-10-11 20:53:05