[confluence] MongoDB > Mongo Extended JSON

44 views
Skip to first unread message

nor...@mongodb.onconfluence.com

unread,
Jan 16, 2013, 7:29:00 PM1/16/13
to mongodb...@googlegroups.com

nor...@mongodb.onconfluence.com

unread,
Jan 16, 2013, 7:29:00 PM1/16/13
to mongodb...@googlegroups.com

Mongo Extended JSON

Page edited by Sam Kleinman


Changes (2)

{hidemenu} {redirect:http://docs.mongodb.org/manual/reference/mongodb-extended-json/}

MongoDB's import and export utilitites, as well as its basic REST interface, support JSON-style access to MongoDB BSON documents. Special representations are used for BSON types that do not have obvious JSON mappings, and multiple representations are allowed for some such types. The REST interface supports three different modes for document output \{ Strict, JS, Shell \}, which serve to control the representations used. MongoDB can understand all of these representations in REST input.

* *Strict* mode produces output conforming to the JSON RFC spec [http://www.json.org].
* *JS* mode produces output that can be processed by most Javascript interpreters. (used by --jsonp option)
* *Shell* / "TenGen" mode produces output that the mongo shell understands. This is basically an enhanced Javascript format.

The following BSON types are represented using special conventions:

|| BSON
Data Type || Strict || JS (via JSONP) || Mongo Shell
("TenGen") || Notes ||
| data_binary | {code}{ "$binary" :
"<bindata>",
"$type" : "<t>" }{code} | {code}{ "$binary" :
"<bindata>",
"$type" : "<t>" }{code} | {code}BinData( <t>, <bindata> ){code} | <bindata> is the base64 representation of a binary string. <t> is the hexadecimal representation of a single byte indicating the data type. |
| data_date | {code}{"$date":<date>}{code} | {code}new Date( <date> ){code} | {code}new Date( <date> ){code} | <date> is the JSON representation of a 64 bit signed integer for milliseconds since epoch UTC (unsigned before version 1.9.1). |
| data_timestamp | {code}{ "$timestamp" :
{"t": <t>,
"i": <i>} }{code} | {code}{ "$timestamp" :
{"t": <t>,
"i": <i>} }{code} | {code}Timestamp(<t>,<i>){code} | <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. |
| data_regex | {code}{ "$regex" : "<sRegex>",
"$options" : "<sOptions>" }{code} | {code}/<jRegex>/<jOptions>{code} | {code}/<jRegex>/<jOptions>{code} | <sRegex> is a string of valid JSON characters. <jRegex> is a string that may contain valid JSON characters and unescaped '"' characters, but may not contain unescaped '/' characters. <sOptions> is a string containing letters of the alphabet. <jOptions> is a string that may contain only the characters 'g', 'i', 'm' and 's' (added in v1.9). Because the JS and TenGen representations support a limited range of options, any nonconforming options will be dropped when converting to this representation. |
| data_oid | {code}{ "$oid" : "<id>" }{code} | {code}{ "$oid" : "<id>" }{code} | {code}ObjectId( "<id>" ){code} | <id> is a 24 character hexadecimal string. \\ |
| data_ref | {code}{ "$ref":"<name>",
"$id" :"<id>" }{code} | {code}{"$ref":"<name>",
"$id":"<id>"}{code} | {code}Dbref("<name>",
"<id>"){code} | <name> is a string of valid JSON characters. <id> is a 24 character hexadecimal string.&nbsp; In the Strict and JS representations, the Strict representation for a data_oid can be used in place of "<id>".\\ |
| data_undefined | {code}{"$undefined":true}{code} | {code}undefined{code} | {code}undefined{code} | The representation for the javascript/bson undefined type |
|data_minkey | {code}{"$minKey" : 1}{code} | {code}{"$minKey" : 1}{code} | {code}MinKey{code} | The representation of the MinKey BSON data type which compares lower than all other types. |
|data_maxkey | {code}{"$maxKey" : 1}{code} | {code}{"$maxKey" : 1}{code} | {code}MaxKey{code} | The representation of the MaxKey BSON data type which compares higher than all other types. |

Full Content

Redirection Notice
This page should redirect to http://docs.mongodb.org/manual/reference/mongodb-extended-json/.

Reply all
Reply to author
Forward
0 new messages