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

Feature Request: make easier to update single fields via Store interface #675

Open
rkingsbury opened this issue May 31, 2022 · 1 comment

Comments

@rkingsbury
Copy link
Collaborator

rkingsbury commented May 31, 2022

Currently the Store interface provides an update method which takes a list of entire documents as an argument. That means in order to modify a single field (to add a tag for example) to documents in an already-existing database, one must do, e.g.

new_docs = []
for doc in Store.query({}):
    doc["tags"].append('new_tag')
    new_docs.append(doc)
Store.update(new_docs)

Which would require download the entirety of every document in the query, which can be slow and inefficient. It would be nice to have a convenience method that can add or modify fields in an existing document without having to download the whole thing.

This is currently possible in maggma by using pure pymongo on the Store._collection attribute, but I think the Store interface should expose this without requiring such detailed knowledge of pymongo.

Store._collection.update_many({<query>}, {'$push': {'tags': 'new_tag'}})
@rkingsbury
Copy link
Collaborator Author

Possibly related to #289

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