i2mint / py2store

Tools to create simple and consistent interfaces to complicated and varied data sources.
MIT License
11 stars 2 forks source link

Mongo-specific `appendable` decorator that uses `._mgc.bulk_write` for extends #83

Open thorwhalen opened 3 years ago

thorwhalen commented 3 years ago

Consider:

from py2store import MongoStore, appendable

M = appendable(MongoStore, item2kv=lambda item: ({'_id': item.pop('_id')}, item))
m = M(db_name='py2store', collection_name='annots_example')
for item in d:
    m.append(item.copy())

Ignoring the mutability of items worry, we could also write:

m.extend(d)

which would be equivalent to the loop.

But not efficient.

Instead, we could have a definition of extend that is specific to mongoDB, and uses bulk_write.