Mongodb & Pymongo: How To Store A Set / List?
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?
Solution 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})}}})
Post a Comment for "Mongodb & Pymongo: How To Store A Set / List?"