Namespace

mongo

kiss.db.mongo

Helper functions to convert filter and sort options to MongoDb syntax

View Source client/core/db/api.js, line 429

Methods

# static convertFilter(filter) → {object}

Convert a filter config into a Mongo query expression

Parameters:
Name Type Description
filter array

The filter config to convert to Mongo syntax

View Source client/core/db/api.js, line 474

The Mongo query expression

object
Example
// If the filter config is:
{
  type: "filter",
  fieldId: "firstName",
  operator: "contains",
  value: "wilson"
}

// It will return:
{firstName: /wilson/}

# static convertFilterGroup(filterGroup) → {object}

Convert a filter config into a Mongo query expression

Parameters:
Name Type Description
filterGroup array

The filter config to convert to Mongo syntax

View Source client/core/db/api.js, line 652

The Mongo query expression

object
Example
// If the filter config is:
{
     type: "group",
     operator: "and",
     filters: [
         {
             type: "filter",
             fieldId: "firstName",
             operator: "contains",
             value: "wilson"
         },
         {
             type: "filter",
             fieldId: "birthDate",
             operator: ">",
             value: "2020-01-01"
         }
     ]
}

// It will return:
{$and: [
     {firstName: /wilson/},
     {birthDate: {$gt: "2000-01-01"}}
]}

# static convertSort(sortArray) → {object}

Convert an array of sort options to Mongo style

Parameters:
Name Type Description
sortArray Array.<object>

The array to format to Mongo style

View Source client/core/db/api.js, line 443

  • A single object with sort options
object
Example
// input:
[{birthDate: "asc"}, {lastName: "desc"}]

// output:
{birthDate: 1, lastName: -1}

# static getFilterFields(filter) → {Array.<string>}

Get all the fields involved in a filter

Parameters:
Name Type Description
filter object

View Source client/core/db/api.js, line 680

The list of field ids

Array.<string>