Google News
logo
TinyDB - Interview Questions
How do you retrieve data from a TinyDB database using the search() method? Can you give an example?
The search() method is used to retrieve data from a TinyDB database. It takes a query argument, which is a Python dictionary representing the search criteria. The keys of the dictionary correspond to the fields in the database, and the values are the values to search for.

Example :
from tinydb import TinyDB, Query
db = TinyDB(‘path/to/database.json’)
table = db.table(‘mytable’)
User = Query()
result = table.search(User.age == 30)
print(result)?
Advertisement