# Advanced logic

Enabling **Advanced logic** allows you to write custom boolean expressions using [MongoDB’s query and projection operators](https://www.mongodb.com/docs/manual/reference/operator/query/), giving you full flexibility over conditional rendering in your flow.

Instead of using a visual logic builder, you write logic directly in JSON format. Each answer variable maps to a field, and standard MongoDB query operators evaluate those fields.

#### Why JSON, not Drag-and-Drop?

While we may support a visual builder in the future, the JSON-based syntax is:

* Powerful and expressive
* Lightweight and easy to copy/paste
* Flexible enough for most complex logic needs

### Common patterns

#### **Both conditions must be true** — `$and`

Enable an item only if **both** conditions are satisfied:

* `distance_to_office` is less than or equal to 75
* `is_qualified` is true

```javascript
{
  "$and": [
    {
      "distance_to_office": {
        "$lte": 75
      }
    },
    {
      "is_qualified": true
    }
  ]
}
```

Read more about [$and](https://docs.mongodb.com/manual/reference/operator/query/and/).

#### **At least one condition is true -** $or

Enable an item if **either** of the following is true:

* `is_parent` is true
* `has_parent_consent` is true

```javascript
{
  "$or": [
    {
      "is_parent": true
    },
    {
      "has_parent_consent": true
    }
  ]
}
```

Read more about [$or](https://docs.mongodb.com/manual/reference/operator/query/or/).

#### **Answer is one of several values** — `$in`

Check if an answer matches **any** value from a list.

Enable if `country` is **CA**, **MX**, or **US**:

```javascript
{
  "country": {
    "$in": [
      "CA",
      "MX",
      "US"
    ]
  }
}
```

Read more about [$in](https://docs.mongodb.com/manual/reference/operator/query/in/).

#### **Answer is&#x20;*****not*****&#x20;in a list of values — `$nin`**

Check that an answer **does not** match any value from a list.

Enable if `state` is **not** NY or PA:

```javascript
{
  "state": {
    "$nin": [
      "NY",
      "PA"
    ]
  }
}
```

Read more about [$nin](https://docs.mongodb.com/manual/reference/operator/query/nin/#mongodb-query-op.-nin).

#### **Answer is defined** — `$exists`

Enable if a variable has **any value** (even `false`):

```javascript
{
  "income": {
    "$exists": true
  }
}
```

This mirrors the behavior of the **Is defined** simple logic operator.

Read more about [$exists](https://docs.mongodb.com/manual/reference/operator/query/exists/).
