如果密钥不存在,我想向集合中添加一条记录.我知道[MongoDB][1]为此提供了upsert
%的折扣,所以我做了一个 Select
db.collection.update({"_id":"key1"},{"_id":"key1"},True)
这似乎奏效了.
然而,在Pymongo documentation中,它表示更新已被弃用,并使用到update_one()
.
但是:
db.collection.update_one({"_id":"key1"},{"_id":"key1"},True)
给予:
raise ValueError('update only works with $ operators')
ValueError: update only works with $ operators
我真的不明白为什么update_one
不同,为什么我需要使用$
操作符.有人能帮忙吗?