📖
Rulecube documentation
v2.4
v2.4
  • Overview
  • Quick Start
  • Tutorial
    • Getting started
    • Create and Run Your First Ruleset
    • Use Constants and Methods
    • Create and Call Functions
    • Adding Testcases
    • Using Lookup Tables
    • Using Entities
    • Using Forms
  • How-to Guides
    • Logging in and Authorization
      • Activate Your Account From an Invitation
      • Log in to Rulecube
      • Change Your Password
      • Recover Your Password
      • Two-factor authentication (2FA)
      • Invite Other Users to Rulecube
      • Edit a User's Role
      • Delete a User
    • Ruleset Development
      • Create a Ruleset
      • Set the Input for a Ruleset
      • Create a Rule
      • Generate Alerts
      • Try out a Ruleset
      • Call a Ruleset from Your Software
      • Entities
        • Create an Entity
        • Drag and Drop a JSON Schema or XSD to create entities
        • Entity instantiation
        • Persisted Entities
      • Constants
        • Constant Tables
      • Functions
      • Built-in Functions
      • Create and Run a Testcase
      • Delete a Ruleset or Components
      • Debugging your Ruleset
    • Create a Workflow
      • Workflow step types
      • Working with documents in a workflow
    • Work with (Environment) Variables
    • Call a Ruleset via Its API From Postman
    • Creating input from JSON Schema
    • Use a Ruleset from Your Software
    • Ruleset Productivity Tips
    • Create an Ockto workflow
    • Alert aggregation
    • Forms
      • Introduction and overview
      • Create a Data table
  • Language Reference
    • Global
    • Array
    • Compression
    • Crypto
    • Date
    • Encryption (deprecated)
    • Finance
    • Http
    • Mail
    • MongoDB
    • Ockto
    • PDF
    • SQL
    • Statistics
    • System
    • UserStore
    • Workflow
Powered by GitBook
On this page
  1. Language Reference

MongoDB

PreviousMailNextOckto

Last updated 2 months ago

Collection of MongoDB functions.

Methods

aggregate

aggregate(connectionString: string, database: string, collection: string, pipeline: { [key: string]: any; }[], options?: { [key: string]: any; })

Equivalent to the MongoDB aggregate function. .

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

pipeline { [key: string]: any; }[]

An array of aggregation pipelines to execute. See the MongoDB aggregation pipeline operators for details.

options { [key: string]: any; }

(optional) The additional options that aggregate() passes to the MongoDB aggregate command. Available only if you specify the pipeline as an array.

Return type

{ [key: string]: any; }

Examples

// Calculates the average of the field 'age' for all documents in the collection 'users':
MongoDB.aggregate("mongodb://localhost:27017", "mydb", "users", [{ $group: { _id: null, avg: { $avg: "$age" } } }]) // { _id: null, avg: 30 }

bulkWrite

bulkWrite(connectionString: string, database: string, collection: string, operations: { [key: string]: any; }[], options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

operations { [key: string]: any; }[]

The sequence of BulkWrite write operations. See MongoDB write operations for details.

options { [key: string]: any; }

Return type

{ [key: string]: any; }

Examples

// Inserts a document into the collection 'users':
MongoDB.bulkWrite("mongodb://localhost:27017", "mydb", "users", [{ insertOne: { document: { name: "John", age: 30 } } }])

deleteMany

deleteMany(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter used to select the documents to remove.

options { [key: string]: any; }

(optional) The additional options for the delete statement. To see available options, see DeleteOptions documentation.

Return type

{ [key: string]: any; }

Examples

// Delete all records of the persons with firstName 'John' from the collection 'users':
MongoDB.deleteMany("mongodb://localhost:27017", "mydb", "users", { firstName: "John" })

delete

delete(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter used to select the document to remove.

options { [key: string]: any; }

(optional) The additional options for the delete statement. To see available options, see DeleteOptions documentation.

Return type

{ [key: string]: any; }

Examples

// Delete a record of a person from the collection 'users':
MongoDB.deleteOne("mongodb://localhost:27017", "mydb", "users", { firstName: "John", lastName: "Doe" })

find

find(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter predicate. If unspecified, then all documents in the collection will match the predicate.

options { [key: string]: any; }

(optional) The additional options for the query. These options modify query behavior and how results are returned. To see available options, see FindOptions documentation.

Return type

{ [key: string]: any; }[]

Examples

// Gets the record of all persons with age higher than 30 from the collection 'users':
MongoDB.find("mongodb://localhost:27017", "mydb", "users", { age: { $gt: 30 } }) 

findOne

findOne(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The query for the find operation.

options { [key: string]: any; }

(optional) The additional options for the query. These options modify query behavior and how results are returned. To see available options, see FindOptions documentation.

Return type

{ [key: string]: any; }

Examples

// Gets the record of person with id 1 from the collection 'users':
MongoDB.findOne("mongodb://localhost:27017", "mydb", "users", { "id": 1 }) // { id: 1, firstName: "John", lastName: "Doe" }

insertMany

insertMany(connectionString: string, database: string, collection: string, documents: { [key: string]: any; }[], options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

documents { [key: string]: any; }[]

The documents to insert.

options { [key: string]: any; }

(optional) The additional options for the insert statement. To see available options, see BulkWriteOptions documentation.

Return type

{ [key: string]: any; }

Examples

// Insert a number of records of a person in the collection 'users':
MongoDB.insertMany("mongodb://localhost:27017", "mydb", "users", [ { firstName: "John", lastName: "Doe" }, { firstName: "Jane", lastName: "Doe" }])

insert

insert(connectionString: string, database: string, collection: string, document: { [key: string]: any; }, options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

document { [key: string]: any; }

The document to insert.

options { [key: string]: any; }

(optional) The additional options for the insert statement. To see available options, see InsertOneOptions documentation.

Return type

{ [key: string]: any; }

Examples

// Insert a record of a person in the collection 'users':
MongoDB.insert("mongodb://localhost:27017", "mydb", "users", { firstName: "John", lastName: "Doe" })

updateMany

updateMany(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, update?: { [key: string]: any; }, options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter used to select the documents to update.

update { [key: string]: any; }

(optional) The update operations to be applied to the documents.

options { [key: string]: any; }

(optional) The additional options for the update statement. To see available options, see UpdateOptions documentation.

Return type

{ [key: string]: any; }

Examples

// Update all records of the persons with firstName 'John' from the collection 'users':
MongoDB.updateMany("mongodb://localhost:27017", "mydb", "users", { firstName: "John" }, { $set: { firstName: "Joel" }})

update

update(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, update?: { [key: string]: any; }, options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The filter used to select the document to update.

update { [key: string]: any; }

(optional) The update operations to be applied to the document.

options { [key: string]: any; }

(optional) The additional options for the update statement. To see available options, see UpdateOptions documentation.

Return type

{ [key: string]: any; }

Examples

// Find a record of a person from the collection 'users' and change its name:
MongoDB.update("mongodb://localhost:27017", "mydb", "users", { firstName: "John", lastName: "Doe" }, { $set: { lastName: "Dow" }})

countDocuments

countDocuments(connectionString: string, database: string, collection: string, filter: { [key: string]: any; }, options?: { [key: string]: any; })

Parameters

connectionString string

The connection string to the MongoDB database.

database string

The name of the database.

collection string

The name of the collection.

filter { [key: string]: any; }

The query for the find operation.

options { [key: string]: any; }

(optional) The additional options for the query. These options modify query behavior. To see available options, see Count documents documentation.

Return type

number

Examples

// Counts the records of all persons with firstName John from the collection 'users':
MongoDB.countDocuments("mongodb://localhost:27017", "mydb", "users", { "firstName": "John" }) // 1

Performs multiple write operations with controls for order of execution. Equivalent to the MongoDB BulkWrite function. .

(optional) The additional options that bulkWrite() passes to the MongoDB bulkWrite command. See the official MongoDB NodeJs documentation for the exact usage of these options. .

Delete all documents that matches the given filter. Equivalent to the MongoDB deleteMany function. .

Delete the first document that matches the given filter. Equivalent to the MongoDB deleteOne function. .

Find and return multiple documents that match the query. Equivalent to the MongoDB find function. .

Find and return the first document that matches the query. Equivalent to the MongoDB findOne function. .

Insert one or more documents. Equivalent to the MongoDB insertMany function. .

Insert one document. Equivalent to the MongoDB insertOne function. .

Update all documents that matches the filter. Equivalent to the MongoDB updateMany function. .

Update the first document that matches the filter. Equivalent to the MongoDB updateOne function. .

Count documents that matches the query. Equivalent to the MongoDB countDocuments function. .

More information
More information
More information
More information
More information
More information
More information
More information
More information
More information
More information
More information