Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pymongo multi update query

I have the following query

DB_HOST = '127.0.0.1'
COLLECTION = 'scraper'
db = pymongo.MongoClient(DB_HOST)[COLLECTION]['scrap']
db.update({'indice':0, 'thread_id':{'$in':list_to_update}},{'updated':'yes'}, multi=True)

where list_to_update is a list of thread_ids where I would like to insert the field 'updated' to 'yes'

I am receiving the following error

pymongo.errors.OperationFailure: multi update only works with $ operators

Any ideas?

like image 693
user2950162 Avatar asked Apr 28 '14 17:04

user2950162


1 Answers

Use the $set operator:

db.update({'indice':0, 'thread_id': {'$in': list_to_update}},
          {'$set': {'updated':'yes'}}, 
          multi=True)
like image 200
vaultah Avatar answered Sep 24 '22 02:09

vaultah