Skip to content

in - Check if a value is equal to any of a number of values

The in function will compare a given value to a collection of other candidates. If the value matches one of the candidates, this function returns true, otherwise false.

Syntax

Like many functions in DataPrime, in supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

in(comparand: any, value: any, ...values: any): bool
comparand: any.in(value: any, ...values: any): bool

Arguments

NameTypeRequiredDescription
comparandanytrueThe keypath to be checked
valueanytrueThe first value to compare against comparand
...valuesanytrueAll subsequent values to compare against comparand

Example - Check if team is in a department

Consider the following document:

{
    "team": "Developers"
},
{
    "team": "Marketing"
},
{
    "team": "QA Testing"
}

We can use the in command to see which of these teams are a member of the Engineering department:

create is_in_engineering from in(team, 'Developers', 'QA Testing', 'Front End Engineers', 'DevOps Team')
create is_in_engineering from team.in('Developers', 'QA Testing', 'Front End Engineers', 'DevOps Team')

This will result in a document with a new field, is_in_engineering which is true if the value of team appears in the in function.

{
    "team": "Developers",
    "is_in_engineering": true
},
{
    "team": "Marketing",
    "is_in_engineering": false
},
{
    "team": "QA Testing",
    "is_in_engineering": true
}