Query for doc_id possible? #470
Replies: 2 comments 6 replies
-
It is possible to do something like this. See the docs. You can remove multiple documents using their doc_id. db.remove(doc_ids=[1,2,3,4]) To get the functionality of db.remove(doc_ids=range(1, 5)) # range(start, stop, step) where start is included and end is not. |
Beta Was this translation helpful? Give feedback.
-
@fortysix2ahead You're correct that this is not supported by TinyDB at the moment. I agree that in some use cases querying by document ID can be useful. The issue is that adding support for this would 1) require a rather large refactoring of TinyDB's internals and 2) potentially break use cases where users use a legimate field called Regarding 1), this is because TinyDB only converts the I think the best option would be to have a custom table class that adds the current document ID during |
Beta Was this translation helpful? Give feedback.
-
This may be a bit of a strange question, but is it possible to use the doc_id for queries? So far, I was not able to find out if and how that would work.
To outline what I was thinking of: imagine I have 3 documents, with doc_ids 1, 2 and 3. I display those to a user (by reusing the doc_id as a regular id):
1: name = Berlin
2: name = London
3: name = Paris
Now the user can decide to remove the latter two with something like: remove_documents( range_from=2, range_to=3). Of course I could introduce a regular document field 'id' so Query().id would work, but the field would have the same value as doc_id. So, why not reuse doc_id?
Beta Was this translation helpful? Give feedback.
All reactions