-2

here is my schema:

"_id" : "tofla@darhoum.dz"

"modif" : 1

"prs" :
{
"pass" : "sdfdsf"
}

"reset" :
[
{
"code" : "1680"
"timr" : "AQQOAAMGCQMcBgodAAYYAgIMDAkLBAEeAAcNAAEG"
}
]

i want to execute lot of operation IN THE SAME LINE OF CODE

yield tornado.gen.Task(db.users.update, {"_id":email}, {"$set":{"prs.pass":password}}, {"$inc":{"modif":1}}, {"$pop":{"reset":1}})

and i got this error:

assert isinstance(upsert, bool), "upsert must be an instance of bool"
AssertionError: upsert must be an instance of bool

but when i split the operation into THREE it works,

yield tornado.gen.Task(db.users.update, {"_id":email}, {"$set":{"prs.pass":password}})
yield tornado.gen.Task(db.users.update, {"_id":email}, {"$pop":{"reset":1}})
yield tornado.gen.Task(db.users.update, {"_id":email}, {"$inc":{"modif":1}})

i found this but thought that it is not the same thing in asynchronous calls, is this mongodb lock?

Update: tried this and worked:

yield [tornado.gen.Task(db.users.update, {"_id":email}, {"$set":{"prs.pass":password}}),
      tornado.gen.Task(db.users.update, {"_id": email}, {"$pop":{"reset":1}}),
      tornado.gen.Task(db.users.update, {"_id":email}, {"$inc":{"modif":1}})]

but isent dangerous?

Community
  • 1
  • 1
Abdelouahab Pp
  • 4,252
  • 11
  • 42
  • 65

1 Answers1

3

You can pass multiple operators in the dict provided to the document argument of update:

yield tornado.gen.Task(db.users.update, {"_id":email}, {"$set":{"prs.pass":password}, "$inc":{"modif":1}, "$pop":{"reset":1}})
dirn
  • 19,454
  • 5
  • 69
  • 74