MongoDB和PyMongo:Upsert多个值

时间:2015-02-09 14:58:31

标签: python mongodb pymongo

我想要像这样:...

response = ips.update(
            { "domain":domain }, {"date":date},
            { "$set":{"visitors":visitors, "totalviews":totalViews} }, upsert=True)

但我明白了:

TypeError: update() got multiple values for keyword argument 'upsert'

1 个答案:

答案 0 :(得分:3)

使用$and运算符来匹配您的更新查询:

db.test.update({"$and": [{date:"date"}, {domain:"domain"}]}, {"$set":{visitors:[]}})

请参阅:MongoDB: Pull complete Key:Array Pair