python - Mongo Update of Array Query using Upsert -


given

  1. menuitems list ['foo', 'bar', 'fooz', 'ball'] ,
  2. menudb collection has 3 records: 'foo', 'bar', 'fooz'

when run

menudb.update({"_id" : {"$in": menuitems}}, {"$addtoset": {"stalecount": 100}}, upsert=true) 

instead of creating new record called 'ball', creates new record called 'objectid("57d730777bc6a465c9124111")'.

is there way make newly created record's '_id' list?

=thanks

you can remove upsert if not want new item in menudb collection. seems id objectid instead of string.

https://docs.mongodb.com/manual/reference/operator/query/in/

you can verify if _id foo exits in collection menudb.update({"_id" : "foo"}, {"$addtoset": {"stalecount": 100})


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -