官术网_书友最值得收藏!

JSON-friendly database

One of the most important reasons for the popularity of MongoDB is that it is a JSON-friendly database. This means that documents are stored and retrieved from MongoDB as JavaScript objects. Internally, this JSON data gets converted to BSON format while getting persisted to the system. So, this gives extreme flexibility, where we can use the same data format from client to server and eventually to the database.

A typical document (record) in a MongoDB collection (table) might look like the following code:

$ mongo 
> db.contacts.find({email: 'jason@kroltech.com'}).pretty()
{
"email" : "jason@kroltech.com",
"phone" : "123-456-7890",
"gravatar" : "751e957d48e31841ff15d8fa0f1b0acf",
"_id" : ObjectId("52fad824392f58ac2452c992"),
"name" : {
"first" : "Jason",
"last" : "Krol"
},
"__v" : 0
}

After examining the preceding output, we can see a key called _id. It is a MongoDB ID which must be encoded as a binary JSON objectID(BSON). If failed to encode, MongoDB won't be able to retrieve or update an object.

主站蜘蛛池模板: 深水埗区| 景泰县| 车致| 麦盖提县| 景洪市| 渝北区| 海盐县| 普兰县| 嘉定区| 克拉玛依市| 琼中| 乌审旗| 宜宾县| 长白| 乌拉特后旗| 航空| 乐昌市| 二手房| 蒙阴县| 怀宁县| 淮北市| 长垣县| 罗山县| 永平县| 台东县| 大名县| 花莲市| 延川县| 梁河县| 临清市| 东宁县| 安福县| 三门峡市| 钟祥市| 北安市| 祁连县| 阳江市| 武宁县| 应用必备| 安塞县| 睢宁县|