Advanced logic

Using arbitrary boolean logic within forms.

With Advanced logic checked, you may enter logic using the MongoDB Query and Projection operators, allowing entry of arbitrary boolean logic.

Your answer variable names map to fields, and the standard query operators are used to evaluate them.

Why no drag and drop advanced logic editor?

We might build one some day, but we've found that using the JSON syntax of MongoDB is very flexible, easy enough to learn, and fully captures the needs of most form flows.

Common patterns

Two conditions are both true, using $and

The following condition would only be enabled when two conditions are both true:

  • a variable named distance_to_office is less than 75

  • a variable named is_qualified is true

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

Read more about $and.

One of two conditions is true, using $or

The following condition would be enabled when either of two conditions are both true:

  • a variable named is_parent is true

  • a variable named has_parent_consent is true

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

Read more about $or.

An answer matches one of a set of values

It's possible to use $or to check for whether an answer equals any of a set of conditions, but it's easier to read if you use $in to check whether an answer matches any of a set of values.

The following condition would be enabled when a variable named country is CA, MX or US:

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

Read more about $in.

An answer is not included in a set of values

To check that an answer is not one of a set of possible values, you can use $nin.

The following condition would be enabled when a variable named state is not NY or PA.

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

Read more about $nin.

An answer is defined

The following condition would be enabled when a variable named income has any value:

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

Note that this is equivalent to using the Is defined simple conditional logic operator.

Read more about $exists.

Last updated