Skip to main contentUpcoming webinar: Make Validation a Practice, Not a Phase. Save your seat.
CONTACT SALESSTART BUILDING

This document is a quick reference for query operators you can use to query anything that's on your content objects.

To experiment with querying your content from within Builder, you can use the Builder API Explorer.

This document covers the following operators:

Comparison Operators

$eq

$gt

$gte

$in

$lt

$lte

$ne

$nin

Logical Operators

$and

$not

$or

$nor

Element Operators

$exists

$type

Array Operators

$elemMatch

Evaluation Operators

$regex

$options

Tip: Custom queries can be slower than typical queries with Builder. Keep this in mind as you write queries, particularly ones that interact with large data sets.

When querying Builder data, you can use MongoDB-style operators. Some examples are below.

When querying a text value that could appear as a number, such as 123, include single quotes around the value. For example, the following query retrieves an entity with an associated product ID of 12345. Notice the pair of single quotes within the double quotes.

{ "data.productId": { "$in": [ "'12345'" ] } }

Keep in mind that, when working with user-entered data, values may not always be what you expect. When using dynamic values, consider always wrapping text values with single quotes.

{ "data.productId": { "$in": [ `'${productId}'` ] } }
OperatorDescription

Use to match values equal to a specified value.

import { builder } from '@builder.io/react';
import type { GetContentOptions } from '@builder.io/sdk';

export const getProduct = (options: GetContentOptions) =>
  builder.get('product', {
    query: { 'data.price': { $eq: 200 } },
    ...options,
  });

Use to match values greater than a specified value.

import { builder } from '@builder.io/react';
import type { GetContentOptions } from '@builder.io/sdk';

export const getProduct = (options: GetContentOptions) =>
  builder.get('product', {
    query: { 'data.price': { $gt: 600 } },
    ...options,
  });

Use to match values greater than or equal to a specified value.

import { builder } from '@builder.io/react';
import type { GetContentOptions } from '@builder.io/sdk';

export const getProduct = (options: GetContentOptions) =>
  builder.get('product', {
    query: { 'data.price': { $gte: 700 } },
    ...options,
  });

Use to match any of the values you specify in an array.

import { builder } from '@builder.io/react';
import type { GetContentOptions } from '@builder.io/sdk';

export const getProduct = (options: GetContentOptions) =>
  builder.get('contact-record', {
    query: { 'data.department': { $in: ['Marketing', 'Engineering'] } },
    ...options,
  });

Use to match values less than a specified value.

import { builder } from '@builder.io/react';
import type { GetContentOptions } from '@builder.io/sdk';

export const getProduct = (options: GetContentOptions) =>
  builder.get('product', {
    query: { 'data.price': { $lt: 455 } },
    ...options,
  });