It's simple, you added extra / red curly braces, try the following:
self.collection.find_and_modify(query={"recid":recid}, update={"$set": {"creation_date": str(datetime.now())}})
UPD (explanation if you are on python> = 2.7):
The error occurs because python thinks that you are trying to create a set with the notation {} :
A set of classes is implemented using dictionaries. Accordingly, the requirements for the elements of the set are the same as for the dictionary keys; namely, that the element defines both __eq __ () and __hash __ ().
In other words, the elements of the set must be hashed: for example, int , string . And you give it a dict , which is not a hashable and cannot be a collection item.
Also see this example:
>>> {{}} Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'dict'
Hope this helps.
source share