How can i search data with using "doc_id < 5"??? #549
Replies: 3 comments 1 reply
-
What is the code you are working with? |
Beta Was this translation helpful? Give feedback.
-
Here I am assuming that "doc_id" is a field in your data, and not the database table's id's. based on the official docs: https://tinydb.readthedocs.io/en/latest/usage.html#queries from tinydb import TinyDB, Query
# Create or load the TinyDB database
db = TinyDB('db.json')
# Define the Query object
query = Query()
# Search for data where doc_id is less than 5
result = db.search(query.doc_id < 5)
# Print the result
print(result) |
Beta Was this translation helpful? Give feedback.
-
This is not possible with TinyDB's query mechanism because it only works with the documents' data, NOT their metadata (i.e. the document ID). I think the most straightforward solution here is something like this: [d for d in db.all() if d.doc_id < 5] Using |
Beta Was this translation helpful? Give feedback.
-
How can i search data with using "doc_id < 5"???
Beta Was this translation helpful? Give feedback.
All reactions