Skip to content

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

Description

@thorwhalen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions