Create a new document
>>>Categories.insert({'test':'test'}) ObjectId('506b563df49a007f73000001')
Yep, created OK.
>>> Categories.find_one({'test':'test'}) {u'test': u'test', u'_id': ObjectId('506b4149f49a007cd0000000')}
Give it a new attribute ‘newAttr’ with value ‘hello’
>>> Categories.update({'_id':Categories.find_one({'test':'test'})['_id']},{'newAttr':'hello'})
Find the same document
>>> Categories.find_one({'test':'test'}) {u'test': u'test', u'_id': ObjectId('506b563df49a007f73000001')}
It hasn’t been updated??
Search for something containing the new attribute:
>>> Categories.find_one({'newAttr':'hello'}) {u'newAttr': u'hello', u'_id': ObjectId('506b4149f49a007cd0000000')}
Its created a separate document instead of updating the previous one??
Any idea how to correct this?
I don’t get the same you get when setting a new field, but I’m using this syntax:
cat.update({'_id':cat.find_one({'test':'test'})['_id']},{'$set':{'newattr':'hello'}})See here for $set explanation.