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

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.

主站蜘蛛池模板: 淮滨县| 临朐县| 柳江县| 锡林郭勒盟| 厦门市| 霍邱县| 萨迦县| 正蓝旗| 红安县| 大宁县| 库车县| 五莲县| 敦煌市| 南陵县| 云梦县| 梁山县| 酒泉市| 虎林市| 南通市| 桐城市| 扎兰屯市| 宝兴县| 长春市| 鄂托克旗| 泰安市| 滨州市| 南城县| 进贤县| 黄石市| 宜宾县| 奉节县| 盈江县| 彭州市| 济南市| 交口县| 安宁市| 揭阳市| 珲春市| 凤山市| 丁青县| 西峡县|