The third argument to PyMongo's update()
is upsert
and must be passed a boolean, not a dictionary. Change your code to:
self.word_counts[source].update({'date':posttime}, {"$inc" : words}, True)
Or pass upsert=True
as a keyword argument:
self.word_counts[source].update({'date':posttime}, {"$inc" : words}, upsert=True)
Your mistake was likely caused by reading about update()
in the MongoDB docs. The JavaScript version of update
takes an object as its third argument containing optional parameters like upsert
and multi
. But since Python allows passing keyword arguments to a function (unlike JavaScript which only has positional arguments), this is unnecessary and PyMongo takes these options as optional function parameters instead.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…