python - Why does db.insert(dict) add _id key to the dict object while using pymongo -
i using pymongo in following way:
from pymongo import * = {'key1':'value1'} db1.collection1.insert(a) print
this prints
{'_id': objectid('53ad61aa06998f07cee687c3'), 'key1': 'value1'}
on console. understand _id added mongo document. why added python dictionary too? did not intend this. wondering purpose of this? using dictionary other purposes , dictionary gets updated side effect of inserting document? if have to, say, serialise dictionary json object, a
objectid('53ad610106998f0772adc6cb') not json serializable
error. should not insert function keep value of dictionary same while inserting document in db.
clearly docs answer question
mongodb stores documents on disk in bson
serialization format. bson
binary representation of json
documents, though contains more data types json.
the value of field can of bson data types, including other documents, arrays, , arrays of documents. following document contains values of varying types:
var mydoc = { _id: objectid("5099803df3f4948bd2f98391"), name: { first: "alan", last: "turing" }, birth: new date('jun 23, 1912'), death: new date('jun 07, 1954'), contribs: [ "turing machine", "turing test", "turingery" ], views : numberlong(1250000) }
to know more bson
Comments
Post a Comment