Queries
After opening a database with a schema, every collection has a typed query API.
Basic shape
await db.users.find(); // allawait db.users.find({ role: 'admin' }); // filteredawait db.users.findOne({ email: 'ali@example.com' }); // first or nullawait db.users.count({ role: 'admin' }); // numberawait db.users.delete({ role: 'user' }); // returns count removedEach method returns its result type inferred from the schema — find() returns Doc[], findOne() returns Doc | null, etc.
Operators
Filter values may be raw scalars (role: 'admin' ≡ equality) or operator objects:
await db.users.find({ age: { $gte: 18, $lt: 65 }, email: { $regex: '@example\\.com$' }, tags: { $in: ['friend', 'family'] }, bio: { $exists: true },});Supported: $gt, $gte, $lt, $lte, $ne, $in, $nin, $exists, $regex.
Where builder
For more dynamic queries:
await db.users .where({ role: 'admin' }) .orderBy('createdAt', 'desc') .limit(20);Transactions
Multi-document writes commit atomically:
await db.transaction(async (tx) => { const user = await tx.users.insert({ email: '...' }); await tx.posts.insert({ authorId: user.id, title: 'Hi' });}); // commit on return, rollback on throwSee the Reactive guide for live() — every query above has a reactive sibling.