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

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.

主站蜘蛛池模板: 巩义市| 河津市| 莱芜市| 阿瓦提县| 科技| 杭锦旗| 黄大仙区| 山丹县| 仁怀市| 鸡泽县| 河源市| 临湘市| 郯城县| 舒城县| 长丰县| 洛南县| 色达县| 五莲县| 土默特右旗| 平江县| 永德县| 灵璧县| 格尔木市| 拜城县| 无锡市| 綦江县| 南和县| 孟津县| 金昌市| 灵丘县| 铁力市| 七台河市| 冷水江市| 融水| 青田县| 郸城县| 花垣县| 鸡西市| 平凉市| 庆云县| 临猗县|