MongoDB Query Builder
The query builder provides a fluent API for building complex MongoDB queries.
Basic Usage
const users = await User.query().where('email', 'test@example.com').many();
Filtering
const users = await User.query().where('age', '>', 18).many();
Sorting
const users = await User.query().sort({ name: -1 }).many();
Limiting and Offsetting
const users = await User.query().limit(10).offset(5).many();
whereIn / whereNotIn
const users = await User.query().whereIn('name', ['Alice', 'Bob']).many();
whereNull / whereNotNull
const users = await User.query().whereNull('email').many();
Raw Queries
const users = await User.query().rawWhere({ email: { $exists: false } }).many();
Best Practices
- Use
.limit()
and.sort()
for pagination. - Use
.rawWhere()
for advanced MongoDB queries.