Skip to content

Query Syntax

await repo.findMany({
where: {
name: 'John',
status: 'active'
}
})
await repo.findMany({
where: {
score: { $gte: 100 },
rank: { $in: ['gold', 'platinum'] }
}
})
OperatorDescriptionExample
$eqEqual{ score: { $eq: 100 } }
$neNot equal{ status: { $ne: 'banned' } }
$gtGreater than{ score: { $gt: 50 } }
$gteGreater than or equal{ level: { $gte: 10 } }
$ltLess than{ age: { $lt: 18 } }
$lteLess than or equal{ price: { $lte: 100 } }
$inIn array{ rank: { $in: ['gold', 'platinum'] } }
$ninNot in array{ status: { $nin: ['banned', 'suspended'] } }
$likePattern match{ name: { $like: '%john%' } }
$regexRegex match{ email: { $regex: '@gmail.com$' } }
await repo.findMany({
where: {
$or: [
{ score: { $gte: 1000 } },
{ rank: 'legendary' }
]
}
})
await repo.findMany({
where: {
$and: [
{ score: { $gte: 100 } },
{ score: { $lte: 500 } }
]
}
})
await repo.findMany({
where: {
status: 'active',
$or: [
{ rank: 'gold' },
{ score: { $gte: 1000 } }
]
}
})
  • % - Matches any sequence of characters
  • _ - Matches single character
// Starts with 'John'
{ name: { $like: 'John%' } }
// Ends with 'son'
{ name: { $like: '%son' } }
// Contains 'oh'
{ name: { $like: '%oh%' } }
// Second character is 'o'
{ name: { $like: '_o%' } }

Uses standard regular expressions:

// Starts with 'John' (case insensitive)
{ name: { $regex: '^john' } }
// Gmail email
{ email: { $regex: '@gmail\\.com$' } }
// Contains numbers
{ username: { $regex: '\\d+' } }
await repo.findMany({
sort: {
score: 'desc', // Descending
name: 'asc' // Ascending
}
})
// First page
await repo.findMany({
limit: 20,
offset: 0
})
// Second page
await repo.findMany({
limit: 20,
offset: 20
})
const result = await repo.findPaginated(
{ page: 2, pageSize: 20 },
{ sort: { createdAt: 'desc' } }
)
// Find active gold players with scores between 100-1000
// Sort by score descending, get top 10
const players = await repo.findMany({
where: {
status: 'active',
rank: 'gold',
score: { $gte: 100, $lte: 1000 }
},
sort: { score: 'desc' },
limit: 10
})
// Search for users with 'john' in username or gmail email
const users = await repo.findMany({
where: {
$or: [
{ username: { $like: '%john%' } },
{ email: { $regex: '@gmail\\.com$' } }
]
}
})