时间:2021-07-01 10:21:17 帮助过:24人阅读
The representation used for the various data types depends on the context in which the JSON is parsed.
The following can parse representations in strict mode with recognition of the type information.
Other JSON parsers, including mongo shell and db.eval(), can parse strict mode representations as key/value pairs, but without recognition of the type information.
The following can parse representations in mongo shell mode with recognition of the type information.
mongoexport and REST and HTTP Interfaces output data in Strict mode.
bsondump outputs in mongo Shell mode.
The following presents the BSON data types and the associated representations in Strict mode and mongoShell mode.
data_binary
Strict Mode | mongo Shell Mode |
{ "$binary": "<bindata>", "$type": "<t>" } | BinData ( <t>, <bindata> ) |
data_date
Strict Mode | mongo Shell Mode |
{ "$date": "<date>" } | new Date ( <date> ) |
In Strict mode, <date> is an ISO-8601 date format with a mandatory time zone field following the template YYYY-MM-DDTHH:mm:ss.mmm<+/-Offset>.
The MongoDB JSON parser currently does not support loading ISO-8601 strings representing dates prior to the Unix epoch. When formatting pre-epoch dates and dates past what your system’s time_ttype can hold, the following format is used:
{ "$date" : { "$numberLong" : "<dateAsMilliseconds>" } }
In Shell mode, <date> is the JSON representation of a 64-bit signed integer giving the number of milliseconds since epoch UTC.
data_timestamp
Strict Mode | mongo Shell Mode |
{ "$timestamp": { "t": <t>, "i": <i> } } | Timestamp( <t>, <i> ) |
data_regex
Strict Mode | mongo Shell Mode |
{ "$regex": "<sRegex>", "$options": "<sOptions>" } | /<jRegex>/<jOptions> |
data_oid
Strict Mode | mongo Shell Mode |
{ "$oid": "<id>" } | ObjectId( "<id>" ) |
<id> is a 24-character hexadecimal string.
data_ref
Strict Mode | mongo Shell Mode |
{ "$ref": "<name>", "$id": "<id>" } | DBRef("<name>", "<id>") |
data_undefined
Strict Mode | mongo Shell Mode |
{ "$undefined": true } | undefined |
The representation for the JavaScript/BSON undefined type.
You cannot use undefined in query documents. Consider the following document inserted into the people 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 the age field has value undefined.
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. See Comparison/Sort Order for more information on comparison order for BSON types.
data_maxkey
Strict Mode | mongo Shell Mode |
{ "$minKey": 1 } | MinKey |
The representation of the MaxKey BSON data type that compares higher than all other types. See Comparison/Sort Order for more information on comparison order for BSON types.
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 insert 9223372036854775807 as a NumberLong 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 of longUnquoted has changed, while longQuoted retains its accuracy:
> db.json.find() { "_id" : ObjectId("54ee1f2d33335326d70987df"), "longQuoted" : NumberLong("9223372036854775807") } { "_id" : ObjectId("54ee1f7433335326d70987e0"), "longUnquoted" : NumberLong("-9223372036854775808") }
MongoDB - Introduction to MongoDB, MongoDB Extended JSON
标签:var and parser ace war amp sig single extend