Stephan K.
Stephan K.

Reputation: 15702

MongoDB and PyMongo: Upsert multiple values

I want to upsert such as this:

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

But I get:

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

Upvotes: 3

Views: 1803

Answers (1)

Stephan K.
Stephan K.

Reputation: 15702

Use the $and operator to match your update query:

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

See: MongoDB: Pull complete Key:Array Pair

Upvotes: 3

Related Questions