msiemens / tinydb

TinyDB is a lightweight document oriented database optimized for your happiness :)
https://tinydb.readthedocs.org
MIT License
6.84k stars 550 forks source link

Query multiple docs by ID #486

Closed pylipp closed 1 year ago

pylipp commented 2 years ago

As a follow-up to #329 , how can I query for multiple docs using their IDs? Like

doc_ids = [1, 2, 5]
db.search(doc_ids=doc_ids)

db.get(doc_id) exists but only for a single document. I could iterate over the list of doc IDs yet this might not be as efficient.

msiemens commented 2 years ago

That's interesting! Maybe we can make db.get() support a list of document IDs as doc_id (similar to .remove() does – altough it does have a doc_ids instead of doc_id). I'll have to think about that!

VermiIIi0n commented 2 years ago

Hi!

I find that in the doc string of get, it says:

Get exactly one document specified by a query or a document ID.

Plus, get already has a parameter doc_id, whilst search doesn't have a similar parameter and returns a list.

I think search(doc_ids=doc_ids) is more reasonable and feels unified.

I plan to implement this feature and want to know why you prefer modifying get.

Atmden commented 2 years ago

И как в итоге получить записи по списку doc_id? Не получается использовать в search массив из doc_ids

patrick-nicodemus commented 1 year ago

I would like to bump this feature request as I have a use-case for it.

keenborder786 commented 1 year ago

Hey , I will have a look into it and start working on it.

keenborder786 commented 1 year ago

@msiemens I have created a PR that inserts the given feature request. Please see #504