The query you supply to update in the first example is not correct, instead of:
query = aCollection.find_one({stuffToFind})
you should have:
query = {stuffToFind}
The reason that the update does not throw an error is that the result of find_one
is a dictionary. Note also that sometimes the above will even work since in the update you are actually asking MongoDB to match the whole document that corresponds to the initial
query. Subsequent uses of query of course in that case will not bring the expected results since the document will have been changed from the update.
The $set updates only the keys that we specify leaving everything else untouched. That means that if we update an embedded object then the whole embedded object will get replaced with what we specify in $set. If we want to pinpoint keys in the embedded object we must use dot notation as you do in the second example.