Is there a way to store python objects directly in mongoDB without serializing them - Stack Overflow
結局pickleを使っている。 あとは、Binary型をfrom bson.binary import Binaryで使っている。
`from pymongo import MongoClient client = MongoClient('localhost', 27017) db = client['test-database'] coll = db.test_collection
the collection is ready now
from bson.binary import Binary import pickle
create a sample object
my_obj = {} my_obj['demo'] = 'Some demo data'
convert it to the raw bytes
thebytes = pickle.dumps(my_obj) coll.insert({'bin-data': Binary(thebytes)})`
元のサイトはpickle.dumpと”s”が抜けてるので間違っている。 「pickle.dumps」を使うこと! ついでにPythonicな変数名にした。