MongoDB

Overview

The MongoDB connector lets your Leena AI Agents store and operate on collections of structured documents directly within the Leena AI platform. It enables Agents to persist business data, look records up on demand, and keep that data in sync as part of automated workflows.

MongoDB is a document-oriented database that stores records as flexible, JSON-like documents. With this connector, Leena AI provisions and manages a dedicated collection for each connection, locks in a schema inferred from a sample you provide, and exposes simple actions so your Agents can create, update, and retrieve records — without your team having to stand up or connect to a separate database.

API Details

The MongoDB connector operates on a Leena AI-managed MongoDB data store. Each connection provisions its own collection inside the platform's data plane, and every record operation runs against that collection through the connector's built-in actions. The connector does not connect to an external MongoDB deployment, so there is no third-party endpoint to configure.

Setup

The MongoDB connector does not use external authentication. Setting up a connection means describing the shape of your data with a sample document, choosing which fields are indexed for filtering, and optionally pre-loading records from an external file source.

Prerequisites

Before setting up the MongoDB connector, ensure you have:

  • Access to your Leena AI workspace with connector management permissions
  • A sample JSON document (or an array of documents) that represents the records you want to store
  • The list of fields you intend to filter records on (these become indexes)
  • (Optional) If you want to pre-load data on creation: an SFTP server hosting the source file, or a publicly reachable Excel/CSV file URL

Get credentials

The MongoDB connector uses no-auth. It does not connect to an external MongoDB instance and does not require API keys, client secrets, or access tokens, so there are no external credentials to create.

If you choose to pre-load data from an SFTP source during setup, you will need your SFTP server details together with either a username and password, or a username and private key. For PGP-encrypted source files, you will also need the ASCII-armored PGP private key (and passphrase, if one is set). These belong to your file source and are not MongoDB credentials.

Add connection

Here is how to add a connection on Leena AI:

  1. Log in to your Leena AI workspace
  2. Navigate to Settings > Integrations
  3. Search for "MongoDB" and select it from the list to add its new connector
  4. Define the collection:
    1. Sample JSON: Paste a sample document, or an array of documents. Leena AI infers the field names and data types (string, number, boolean, object, array, null) from this sample and locks the schema when the connection is created.
    2. Indexed fields: The fields you want to filter on later. Each row takes one or more field names and an optional Unique toggle. Use a single field for a simple index, or comma-separate field names for a compound index (field order matters). A maximum of 5 indexes is allowed per collection, and a compound index can span up to 3 fields. At least one indexed field is required, because the Update and List actions can only filter on indexed fields.
  5. (Optional) Configure an initial data import to populate the collection in the background after creation. Select an Import source:
    1. SFTP: Provide the SFTP host, port (default 22), auth type (username + password, or username + private key), username, password or private key, file path, sheet name (XLSX only), and header row (1-based). For PGP-encrypted files, enable the PGP option and supply the PGP private key and passphrase.
    2. Excel URL: Provide the Excel/CSV file URL, sheet name (XLSX only), and header row (1-based).
    3. Notification email: If set, you receive a success or failure email once the import completes.
  6. (Optional) Configure a recurring sync to re-import the source on a cron schedule. Set the minute, hour, day-of-month, month, and day-of-week fields, the IANA timezone, an optional end date, and options to email on every run or pause the schedule. Note that each recurring run drops the rows loaded from the source and replaces them, so records added manually via Insert or Update actions are not preserved across a sync.
  7. Save the configuration. Leena AI provisions the collection with the locked schema and indexes, and queues any requested import.

Actions

The following actions are supported for the MongoDB connector:

Insert a single record

Adds one document to the connection's collection. The document is validated against the locked schema — required fields must be present and declared types must match — before it is stored. Documents must be 2 MB or smaller. This action inserts a single object only; to add several records at once, use the Bulk update action.

Input Parameters

This action takes a single parameter:

Mandatory

NameDescription
DataA single JSON object representing the record to insert. Fields declared in the schema must match their declared types; extra fields not in the schema are stored as-is.

Response

Upon successful insertion, the action returns the generated identifier of the new document (insertedId).

Update records by filter

Updates the record or records that match a filter. The filter must reference indexed fields, and the update is applied with set semantics, so only the fields you provide are changed. Optionally, the action can create a record when no match is found.

Input Parameters

Here are the input parameters required to set up this action:

Mandatory

NameDescription
FilterA JSON object identifying the record(s) to update. It can only reference indexed fields and cannot be empty.
Update dataA JSON object of the fields to set on the matched record(s).

Optional

NameDescription
If record doesn't exist, create itWhen enabled, performs an atomic find-or-create. If no record matches the filter, the combined filter and update must satisfy the full schema (all required fields present).

Response

Upon successful update, the action returns the number of records matched and modified, along with the identifier of any record created through upsert (matchedCount, modifiedCount, upsertedId).

Bulk update or upsert records

Updates or upserts many records in a single call. Each record in the array is matched to an existing row by one key field that you choose, and missing rows can optionally be created. A maximum of 1000 records can be processed per call.

Input Parameters

Here are the input parameters required to set up this action:

Mandatory

NameDescription
Match by (key field)The field used to match each record against an existing row (for example, employeeId). This field must be on a single-field unique index in the connection's configuration.
RecordsA JSON array of record objects. Each object must include the key field. A maximum of 1000 records is allowed per call.

Optional

NameDescription
If a record doesn't exist, create itWhen enabled, performs an atomic find-or-create per record. Every record must satisfy the full schema (all required fields present).

Response

Upon completion, the action returns the counts of matched, modified, and upserted records, along with the identifiers of any newly created records and their position in the input array (matchedCount, modifiedCount, upsertedCount, upsertedIds).

List or search records

Retrieves records from the collection. With no filter, it returns all records up to the configured limit; with a filter on indexed fields, it returns only matching records. The action supports pagination and sorting.

Input Parameters

All parameters for this action are optional:

Optional

NameDescription
FilterA JSON object used to match records. It can only reference indexed fields. Leave it empty or pass {} to return all records (subject to the limit).
LimitThe maximum number of records to return. Defaults to 100, with a maximum of 1000.
SkipThe number of records to skip, used for pagination. Defaults to 0.
SortA JSON object specifying sort order, where 1 is ascending and -1 is descending.

Response

The action returns the matching records together with a count of how many were returned (count, records).