Skip to main content
Version: v0.15
info

This section is only relevant if you're interested in building your own Conduit modules.

Query Operations

The database module allows you to conveniently query your data without the need of writing complex SQL queries.
Schemas can be manipulated through model controller objects automatically generated by the module itself.

Suppose you're building a module that keeps track of superheroes and villains.
Having registered your schemas, this is how you'd query for villains facing off against Mammothman, returning their name, antagonist and universe fields.
You'll get up to 3 results, containing the 7th, 8th and 9th entries matching the above criteria due to the specified pagination (skip, limit).
Your villains are going to be sorted in a descending order based on their name field.
Through the use of populate, the antagonist relation field ids are going to be replaced by the entire Antagonist entry objects in reference.

Query Example using a Villains model controller
const mammothVillains = Villains.getInstance().findMany(
{ antagonist: "Mammothman" }, // query
"name antagonist universe", // select
6, // skip
3, // limit
"-name", // sort
"antagonist", // populate
)

Throughout the examples listed below, we'll be utilizing SchemaName to represent our model controllers.

Comparison Operators

$in

The $in operator selects the documents where the value of a field equals any value in the specified array.
To specify an $in expression, use the following prototype:

Syntax
{ field: { $in: [<value1>, <value2>, ... <valueN> ] } }
Example
const documents = SchemaName.getInstance().findMany({ _id: { $in: ids})

Where ids is an array of object ids.

$contains

In mongoDB $contains and $in operator does the same thing.
However in SQL DBs $contains differs from $in operator.

Syntax
{ field: { $in: [<value1>, <value2>, ... <valueN> ] } }

$nin

  • Selects the documents when a field value is not inside an array.
  • Selects the documents when the field does not exist.
Syntax
{ field: { $nin: [ <value1>, <value2> ... <valueN> ] } }
Example
const documents = SchemaName.getInstance().findMany({ id : { $nin : ids} })

Where ids is an array of object ids.

$eq

Returns the documents where the value of a field is equal with a specified value.

Syntax
{ <field>: { $eq: <value> } }

or

{ <field>: <value> }
Example
const documents = SchemaName.getInstance().findMany({ provider: { $eq: "conduit"})

$ne

Returns the documents where the value of a field isn't equal with a specified value.

Syntax
{ <field>: { $eq: <value> } }
Example
const documents = SchemaName.getInstance().findMany({ provider: { $ne: "conduit" })

$lt

Returns the documents where the value of a field is less than a specified value.

Syntax
{ <field>: { $lt: <value> } }
Example
const documents = SchemaName.getInstance().findMany({ age: { $lt: 18 })

$lte

Returns the documents where the value of a field is less or equal to a specified value.

Syntax
{ <field>: { $lte: <value> } }
Example
const documents = SchemaName.getInstance().findMany({ age: { $lte: 18 })

$gt

Returns the documents where the value of a field is greater than a specified value.

Syntax
{ <field>: { $gt: <value> } }
Example
const documents = SchemaName.getInstance().findMany({ age: { $gt: 18 })

$gte

Returns the documents where the value of a field is greater or equal to a specified value.

Syntax
{ <field>: { $gte: <value> } }
Example
const documents = SchemaName.getInstance().findMany({ age: { $gte: 18 })

$regex

Returns the documents where the value of a field matches with the specified regex.

Syntax
{ <field>: { $regex: <regex> } }
Example
const documents = SchemaName.getInstance().findMany({ name: { $regex: '.*conduit.*' })

Logical Operators

$or

Performs logical OR operation on two or more expressions and returns the documents that satisfy at least one.

Syntax
{ $or: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] }
Example
const documents = SchemaName.getInstance().findMany( { $or: [ { price: { $lt: 20 } }, { expires: 10 } ] } )

$and

Performs logical AND operation on two or more expressions and returns the documents that satisfy all the expressions.

Syntax
{ $and: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] }
Example
const documents = SchemaName.getInstance().findMany( { $and: [ { price: { $lt: 20 } }, { expires: 10 } ] } )

$not

Performs logical NOT operation on an <operator expression>s and returns the documents do not match the expression.

Syntax
{ field: { $not: { <operator-expression> } } }
Example
const documents = SchemaName.getInstance().findMany( { price: { $not: { $lte: 5 } } } )

Query parameters

Select

Syntax
select = "<fieldA> <fieldB>"

Skip

Skip value defines how many documents will be skipped.

Syntax
skip = <int>

Limit

Limit value defines how many documents you are gonna fetch.

Syntax
limit = <int>

Sort

Database module supports descending and ascending sorting order. Skip value defines how many documents will be skipped.

Syntax
sort = "<fieldName>"  // ascending order
sort = "-<fieldName>" // descending order

Populate

You may choose either one of the following syntax formats:

Array Syntax
populate = ["<objectFieldA>", "<objectFieldB>"]
String Syntax
populate = "<objectFieldA>,<objectFieldB>"