Operators
The Data API evaluates queries, updates and pipelines with MongoDB semantics. These operators are supported; JavaScript operators never run.
| Operator | Example |
|---|---|
$eq / plain value |
{ status: 'Won' }, { status: { $eq: 'Won' } } |
$ne |
{ status: { $ne: 'Lost' } } |
$gt $gte $lt $lte |
{ dealValue: { $gte: 1000, $lt: 5000 } } |
$in $nin |
{ status: { $in: ['Lead', 'Contacted'] } } |
$and $or $nor |
{ $or: [{ status: 'Won' }, { dealValue: { $gt: 5000 } }] } |
$not |
{ name: { $not: /^test/ } } |
$exists |
{ email: { $exists: true } } |
$type |
{ notes: { $type: 'string' } } |
$regex $options |
{ name: { $regex: '^ad', $options: 'i' } } or { name: /^ad/i } |
$all |
{ tags: { $all: ['vip', 'cafe'] } } |
$elemMatch |
{ items: { $elemMatch: { qty: { $gt: 5 } } } } |
$size |
{ tags: { $size: 2 } } |
Dot paths reach into JSON fields: { 'address.city': 'Lahore' }. Comparisons with date fields
convert the value to the field’s precision first.
Update
Section titled “Update”| Operator | Example |
|---|---|
$set |
{ $set: { status: 'Won', 'address.city': 'Lahore' } } |
$unset |
{ $unset: { phone: '' } } |
$inc |
{ $inc: { visits: 1 } } |
$mul |
{ $mul: { price: 1.1 } } |
$min $max |
{ $max: { highScore: 120 } } |
$rename |
{ $rename: { nick: 'nickname' } } |
$push |
{ $push: { tags: { $each: ['a', 'b'] } } } |
$addToSet |
{ $addToSet: { tags: 'vip' } } |
$pull |
{ $pull: { tags: 'old' } } |
$pop |
{ $pop: { queue: -1 } } |
$currentDate |
{ $currentDate: { lastSeen: true } } |
$setOnInsert |
{ $setOnInsert: { createdBy: 'import' } } (with upsert) |
Aggregation
Section titled “Aggregation”Stages: $match, $project, $addFields, $set, $unset, $group, $sort, $skip,
$limit, $count, $unwind, $lookup, $sortByCount, $replaceRoot, $sample,
$bucket, $facet.
Accumulators: $sum, $avg, $min, $max, $first, $last, $push, $addToSet, $count.
Expressions: arithmetic ($add, $subtract, $multiply, $divide, $mod, $round,
$abs), comparison ($eq, $gt, $cmp…), boolean ($and, $or, $not), conditional ($cond,
$ifNull, $switch), string ($concat, $toUpper, $toLower, $substrCP, $split, $trim),
array ($size, $filter, $map, $arrayElemAt, $in, $slice), type ($toDate, $toString,
$toInt), date ($year, $month, $dayOfMonth, $dateToString).
Not available: $out, $merge, and JavaScript operators ($where, $function,
$accumulator). Pipelines have at most 50 stages.
Made by Faeiz Furqan