tinydb icon indicating copy to clipboard operation
tinydb copied to clipboard

Query multiple docs by ID

Open pylipp opened this issue 3 years ago • 1 comments

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.

pylipp avatar Aug 19 '22 10:08 pylipp

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!

msiemens avatar Aug 25 '22 17:08 msiemens

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.

VermiIIi0n avatar Oct 11 '22 14:10 VermiIIi0n

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

Atmden avatar Oct 25 '22 07:10 Atmden

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

patrick-nicodemus avatar Jan 19 '23 15:01 patrick-nicodemus

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

keenborder786 avatar Jan 22 '23 20:01 keenborder786

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

keenborder786 avatar Jan 23 '23 10:01 keenborder786