I'm new with MOngoDB ( coming from CouchDB ) and I am having issues with adding new attributes to my documents in MongDB using the MonDB python driver.
For example, I have the following document:
{ '_id':123456, 'text':"this is nice" }
And I want to insert a new attribute, for example:
{ '_id':123456, 'text':"this is nice", 'created_time':datetime.datetime.now() }
How do I go about adding the created_time attribute to my document?
Thanks!
To add field or fields to embedded documents (including documents in arrays) use the dot notation. See example. To add an element to an existing array field with $addFields , use with $concatArrays .
The insert() Method To insert data into MongoDB collection, you need to use MongoDB's insert() or save() method.
db.collection.update({'_id' : ObjectId(...)}, {'$set' : {'create_time' : datetime(..) }})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With