How can i search data with using "doc_id < 5"??? #549
Replies: 3 comments 1 reply
|
What is the code you are working with? |
0 replies
|
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) |
1 reply
|
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 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
How can i search data with using "doc_id < 5"???
All reactions