Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thorwhalen opened this issue Feb 23, 2021 · 0 comments

Comments

@thorwhalen
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant