问题
Apparently it is not possible and the best advice I found so far is to use dict but this is not what I want. Is there still a way to store a set / list in MongoDB?
回答1:
With mongo you have to pass a json (which in python we can essentially think of as a dict) in order to do anything really, so say you want to add a list or set of numbers to the hamburgers
field in your collection, you would prepare it as follows:
db.your_collection.update({'$push': {'hamburgers': {$each: [1, 2, 3, 4]}}})
if it's a set, you cant convert it to a list
db.your_collection.update({'$push': {'hamburgers': {$each: list({1, 2, 3, 4})}}})
来源:https://stackoverflow.com/questions/36288794/mongodb-pymongo-how-to-store-a-set-list