Skip to main content

Setup simple tables or collections

# If data is in a format natively supported by MongoDB, we don't need to do anything.
# However to manually specify datatypes, do as below
from superduper import Schema, Document
from superduper_pillow import pil_image
from superduper.components.datatype import pickle_serializer

fields = {
'serialized_content': pickle_serializer,
'img_content': pil_image,
}

schema = Schema(identifier="my-schema", fields=fields)

# Add schema to system
db.apply(schema)

# Now assert `Document` instances, specifying this schema
db['documents'].insert_many([
Document({
'serialized_content': item,
'img_content': img,
}, schema='my-schema')
for item, img in data
])