Skip to main content

Filtering nodes

MongoDB query languageโ€‹

Orgvueโ€™s export API allows for node level filtering and supports MongoDB operators.

This enables filtering of Orgvue data in JSON format using a schema like the following:

{
"filter": {
"area": {
"$in": [
"Head Office",
"Manchester",
"Birmingham"
]
},
"startDate": {
"$gt": "2020-01-01T00:00:00.000Z"
},
"gender": "Male",
"grade": {
"$gt": 6
}
}
}

Filteringโ€‹

Using a MongoDB query object, you can filter out nodes from the result that would be exported to you, after calculations have occurred. If a filter is not supplied then all rows will be exported.

Operators are used in logical statements to determine the equality or difference between variables or values

The table below contains all MongoDB query operators currently supported by the export API filtering feature:

NameDescription
$gtMatches values that are greater than a specified value.
$gteMatches values that are greater than or equal to a specified value.
$inMatches any of the values specified in an array.
$ltMatches values that are less than a specified value.
$lteMatches values that are less than or equal to a specified value.
$neMatches values that are not equal to a specified value.
$ninMatches none of the values specified in an array.
note

The API does not currently support an operator for equality. In order to match a single value of a field set the property key as the key and value as the value.

For example, you may want to find all of the nodes in a people dataset where the value of the "Department" property is "Engineering".

"Department": "Engineering"

$ne: The "Not Equal to" Operatorโ€‹

The $ne operator can be used to find any nodes with a property that is not equal to the specified value.

For example you may want to retrieve all nodes whose "employeeGrade" does not equal "Executive".

"employeeGrade": {
"$ne": "Executive"
}

$gt: The "Greater Than" Operatorโ€‹

$gt can be used to find any nodes with a property whose value is greater than a given number.

For example, if you have a people dataset then you may want to only return nodes whose "age" is greater than 45.

"age": {
"$gt": 45
}

$lt: The "Less Than" Operatorโ€‹

$lt can be used to query any nodes with a property whose value is less than a given number.

For example, given a people dataset you may want to retrieve any employees who have less than 5 direct reports.

"directReports": {
"$lt": 5
}

$gte: The "Greater Than or Equal to" Operatorโ€‹

$gte can be used to query any nodes with a property whose value is greater than or equal to a given number.

For example, given a people dataset you may want to retrieve any employees whose salary is greater than $50,000.

"salary": {
"$gte": 50000
}

$lte: The "Less Than or Equal to" Operatorโ€‹

$lte can be used to query any nodes with a property whose value is less than or equal to a given number.

For example, given a positions dataset you may want to retrieve any positions whose cost to hire is less than or equal to $2,000.

"hiringCost": {
"$lte": 2000
}

$in: The "In" Operatorโ€‹

The $in operator can be used in any scenarios where you want to query nodes for more than one value in a property.

  • You have positions that are Rejected or Pending Approval in Orgvue and you wish to filter to just those records.
  • You wish to export nodes from multiple departments, like Finance, Research, HR.
  • You want to have a combination of data where each row must satisfy both conditions.

The example below shows an example of exporting the above described positions in all three departments

"department": {
"$in": [ "Finance", "Research", "HR"]
},
"position": {
"$in" : ["Rejected", "Pending Approval"],
},

$nin: The "Not In" operatorโ€‹

The $nin operation is the inverse of the $in operator. It can be used to filter out multiple values from the exported nodes.

For example, given a people dataset you may want to exclude any employees located in either the UK or Germany.

"country": {
"$nin": ["UK", "Germany"]
}

Filter by Dateโ€‹

For your dates to be recognised and queried, they must be in one of the following forms:

  • A short ISO 8601 string, like "2022-10-27".
  • An extended ISO 8601 string, like "2022-10-27T09:50:31.832Z", or "2022-10-27T09:50:31", or "2022-10-27T09:50".

For example:

{
"filter": {
"startDate": {
"$in": ["2020-01-01", "2020-02-01", "2020-03-01"]
},
"_modifiedAt": {
"$gt": "2023-01-06T15:00:00.000Z"
}
}
}