python - Mongo Update of Array Query using Upsert -
given
- menuitems list ['foo', 'bar', 'fooz', 'ball'] ,
- 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
Post a Comment