Hear from Salesforce leaders on how to create and deploy Agentforce agents.
Contact Us 1-800-596-4880

Mongo DB Connector API Reference

MongoDB is an open source, high-performance, schema-free, document-oriented database that manages collections of BSON documents.

Additional Info

Requires Mule Enterprise License

Yes  

Requires Entitlement

No  

Mule Version

3.6.0 or higher

Configs


Configuration

<mongo:config>

Connection Management

Attributes

Name Java Type Description Default Value Required

name

StringLeaving the Site

The name of this configuration. With this name can be later referenced.

x 

username

StringLeaving the Site

the username to use for authentication.

 

password

StringLeaving the Site

the password to use for authentication. If the password is null or whitespaces only, the connector won't use authentication and username must be empty too.

 

database

StringLeaving the Site

Name of the database

x 

host

StringLeaving the Site

A list of MongoDB instance, with the format host:port, separated by commas.

Example: 127.0.0.1:27017, 192.168.1.2:27017

localhost:27017

 

connectionsPerHost

IntegerLeaving the Site

The number of connections allowed per host (the pool size, per host)

 

threadsAllowedToBlockForConnectionMultiplier

IntegerLeaving the Site

Multiplier for connectionsPerHost for # of threads that can block.

 

maxWaitTime

IntegerLeaving the Site

The max wait time for a blocking thread for a connection from the pool in ms.

 

connectTimeout

IntegerLeaving the Site

The connection timeout in milliseconds; this is for establishing the socket connections (open). 0 is default and infinite.

30000

 

socketTimeout

IntegerLeaving the Site

The socket timeout. 0 is default and infinite.

 

ssl

boolean

This is for enabling an SSL connection. It is disabled by default.

false

 

authenticationDatabase

StringLeaving the Site

 


Connection String

<mongo:config-connection-string>

Connection Management

Attributes

Name Java Type Description Default Value Required

name

StringLeaving the Site

The name of this configuration. With this name can be later referenced.

x 

connectionString

StringLeaving the Site

x 

Processors


Add user

<mongo:add-user>

Adds a new user for this db

XML Sample

<mongo:add-user config-ref="Mongo_DB__Configuration" newUsername="myUser" newPassword="myPassword"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

newUsername

StringLeaving the Site

Name of the user

x 

newPassword

StringLeaving the Site

Password that will be used for authentication

x 

Returns

Return Java Type Description

DocumentLeaving the Site

Result of the operation


Drop database

<mongo:drop-database>

Drop the current database

XML Sample

<mongo:drop-database config-ref="Mongo_DB__Configuration"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 


List collections

<mongo:list-collections>

Lists names of collections available at this database

XML Sample

<mongo:list-collections config-ref="Mongo_DB__Configuration"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

Returns

Return Java Type Description

IterableLeaving the Site<StringLeaving the Site>

the list of names of collections available at this database


Exists collection

<mongo:exists-collection>

Answers if a collection exists given its name

XML Sample

<mongo:exists-collection config-ref="Mongo_DB__Configuration" collection="aColllection"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection

#[payload]

 

Returns

Return Java Type Description

boolean

if the collection exists


Drop collection

<mongo:drop-collection>

Deletes a collection and all the objects it contains. If the collection does not exist, does nothing.

XML Sample

<mongo:drop-collection config-ref="Mongo_DB__Configuration" collection="aCollection"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection to drop

#[payload]

 


Create collection

<mongo:create-collection>

Creates a new collection. If the collection already exists, a MongoException will be thrown.

XML Sample

<mongo:create-collection config-ref="Mongo_DB__Configuration" collection="aCollection" capped="true"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection to create

x 

capped

boolean

if the collection will be capped

false

 

maxObjects

IntegerLeaving the Site

the maximum number of documents the new collection is able to contain

 

size

IntegerLeaving the Site

the maximum size of the new collection

 


Insert document

<mongo:insert-document>

Inserts a document in a collection, setting its id if necessary.

XML Sample

<mongo:insert-document config-ref="Mongo_DB__Configuration" collection="Employees">
        </mongo:insert-document>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection where to insert the given document.

x 

document

DocumentLeaving the Site

a DocumentLeaving the Site instance.

#[payload]

 

Returns

Return Java Type Description

StringLeaving the Site

the id that was just inserted


Insert documents

<mongo:insert-documents>

Inserts a list of documents in a collection, setting its id if necessary.

XML Sample

<mongo:insert-documents config-ref="Mongo_DB__Configuration" collection="Employees">
        </mongo:insert-documents>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection where to insert the given document.

x 

documents

ListLeaving the Site<DocumentLeaving the Site>

a ListLeaving the Site of DocumentLeaving the Site.

#[payload]

 

ordered

boolean

indicates if the list of write operations is ordered or unordered. By default, ff an error occurs during the processing of one of the write operations, MongoDB will return without processing any remaining write operations in the list.

true

 

Returns

Return Java Type Description

DocumentLeaving the Site

a DocumentLeaving the Site with the operation result


Update documents

<mongo:update-documents>

Updates documents that matches the given query. If query is not specified, all documents are retrieved. If parameter multi is set to false, only the first document matching it will be updated. Otherwise, all the documents matching it will be updated.

XML Sample

<mongo:update-documents config-ref="Mongo_DB__Configuration" collection="myCollection" query-ref="#[payload]">
        </mongo:update-documents>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection to update

x 

query

DocumentLeaving the Site

the DocumentLeaving the Site query object used to detect the element to update.

 

element

DocumentLeaving the Site

the DocumentLeaving the Site mandatory object that will replace that one which matches the query.

#[payload]

 

multi

boolean

if all or just the first document matching the query will be updated

true

 

Returns

Return Java Type Description

DocumentLeaving the Site

a DocumentLeaving the Site with the update status


Update documents by function

<mongo:update-documents-by-function>

Update documents using a mongo function. If query is not specified, all documents are retrieved.

XML Sample

<mongo:update-documents-by-function config-ref="Mongo_DB__Configuration" collection="myCollection" element-ref="#[payload]" upsert="true" function="$set">
        </mongo:update-documents-by-function>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection to update

x 

function

StringLeaving the Site

the function used to execute the update

x 

query

DocumentLeaving the Site

the DocumentLeaving the Site query document used to detect the element to update.

 

element

DocumentLeaving the Site

the DocumentLeaving the Site mandatory document that will replace that one which matches the query.

#[payload]

 

upsert

boolean

if the database should create the element if it does not exist.

false

 

multi

boolean

if all or just the first document matching the query will be updated.

true

 

Returns

Return Java Type Description

DocumentLeaving the Site

a DocumentLeaving the Site with the update status.


Update documents by functions

<mongo:update-documents-by-functions>

Update documents using one or more mongo function(s). If query is not specified, all documents are retrieved. If there are duplicated operators. Only the last one will be executed.

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection to update

x 

query

DocumentLeaving the Site

the DocumentLeaving the Site query document used to detect the element to update

 

functions

DocumentLeaving the Site

the DocumentLeaving the Site of functions used to execute the update. e.g. <$set,{"key":123}>

#[payload]

 

upsert

boolean

whether the database should create the element if it does not exist

false

 

multi

boolean

if all or just the first document matching the query will be updated

true

 

Returns

Return Java Type Description

DocumentLeaving the Site

a DocumentLeaving the Site with the update status.


Save document

<mongo:save-document>

Inserts or updates a document based on its object _id.

XML Sample

<mongo:save-document config-ref="Mongo_DB__Configuration" collection="myCollection">
        </mongo:save-document>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the collection where to insert the object

x 

document

DocumentLeaving the Site

the mandatory DocumentLeaving the Site document to insert.

#[payload]

 


Remove documents

<mongo:remove-documents>

Removes all the documents that match the a given optional query. If query is not specified, all documents are removed. However, please notice that this is normally less performant that dropping the collection and creating it and its indices again

XML Sample

<mongo:remove-documents config-ref="Mongo_DB__Configuration" collection="myCollection">
        </mongo:remove-documents>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the collection whose elements will be removed

x 

query

DocumentLeaving the Site

the optional DocumentLeaving the Site query object. Documents that match it will be removed.

#[payload]

 


Map reduce objects

<mongo:map-reduce-objects>

Transforms a collection into a collection of aggregated groups, by applying a supplied element-mapping function to each element, that transforms each one into a key-value pair, grouping the resulting pairs by key, and finally reducing values in each group applying a suppling 'reduce' function.

Each supplied function is coded in JavaScript.

Note that the correct way of writing those functions may not be obvious; please consult MongoDB documentation for writing them.

XML Sample

<mongo:map-reduce-objects config-ref="Mongo_DB__Configuration" collection="myCollection" mapFunction="myMapFunction" reduceFunction="myReduceFunction"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection to map and reduce

x 

mapFunction

StringLeaving the Site

a JavaScript encoded mapping function

x 

reduceFunction

StringLeaving the Site

a JavaScript encoded reducing function

x 

outputCollection

StringLeaving the Site

the name of the output collection to write the results, replacing previous collection if existed, mandatory when results may be larger than 16MB. If outputCollection is unspecified, the computation is performed in-memory and not persisted.

 

Returns

Return Java Type Description

IterableLeaving the Site<DocumentLeaving the Site>

an iterable that retrieves the resulting collection of DocumentLeaving the Site


Count documents

<mongo:count-documents>

Counts the number of documents that match the given query. If no query is passed, returns the number of elements in the collection

XML Sample

<mongo:count-documents config-ref="Mongo_DB__Configuration" collection="myCollection" query-ref="dbObject"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the target collection

x 

query

BsonLeaving the Site

the optional DocumentLeaving the Site query for counting documents. Only documents matching it will be counted. If unspecified, all documents are counted.

#[payload]

 

Returns

Return Java Type Description

long

the amount of documents that matches the query


Find documents

<mongo:find-documents>

Finds all documents that match a given query. If no query is specified, all documents of the collection are retrieved. If no fields object is specified, all fields are retrieved.

XML Sample

<mongo:find-documents config-ref="Mongo_DB__Configuration" collection="myCollection" limit="5" numToSkip="10" query-ref="#[payload]" sortBy-ref="#[new org.bson.Document()]">
            <mongo:fields>
                <mongo:field>field1</mongo:field>
                <mongo:field>field2</mongo:field>
            </mongo:fields>
        </mongo:find-documents>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the target collection

x 

query

DocumentLeaving the Site

the optional DocumentLeaving the Site query document. If unspecified, all documents are returned.

#[payload]

 

fields

ListLeaving the Site<StringLeaving the Site>

alternative way of passing fields as a literal List

 

numToSkip

IntegerLeaving the Site

number of documents skip (offset)

 

limit

IntegerLeaving the Site

limit of documents to return

 

sortBy

DocumentLeaving the Site

indicates the DocumentLeaving the Site used to sort the results

 

Returns

Return Java Type Description

IterableLeaving the Site<DocumentLeaving the Site>

an iterable of DocumentLeaving the Site


Find one document

<mongo:find-one-document>

Finds the first document that matches a given query. Throws a MongoException if no one matches the given query

XML Sample

<mongo:find-one-document config-ref="Mongo_DB__Configuration" collection="myCollection">
            <mongo:fields>
                <mongo:field>field1</mongo:field>
                <mongo:field>field2</mongo:field>
            </mongo:fields>
        </mongo:find-one-document>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the target collection

x 

query

DocumentLeaving the Site

the mandatory DocumentLeaving the Site query document that the returned object matches.

#[payload]

 

fields

ListLeaving the Site<StringLeaving the Site>

alternative way of passing fields as a literal List

 

failOnNotFound

BooleanLeaving the Site

Flag to specify if an exception will be thrown when no object is found. For backward compatibility the default value is true.

true

 

Returns

Return Java Type Description

DocumentLeaving the Site

a DocumentLeaving the Site that matches the query. If nothing matches and the failOnNotFound is set to false, null will be returned


Find one and update document

<mongo:find-one-and-update-document>

Finds and update the first document that matches a given query. When returnNew = true, returns the updated document instead of the original document.

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the target collection

x 

query

DocumentLeaving the Site

the DocumentLeaving the Site query that the returned object matches.

 

element

DocumentLeaving the Site

the DocumentLeaving the Site mandatory object that will replace that one which matches the query

#[payload]

 

fields

ListLeaving the Site<StringLeaving the Site>

alternative way of passing fields as a literal List

 

returnNewDocument

BooleanLeaving the Site

Flag to specify if the returning DocumentLeaving the Site should be the updated document instead of the original. Defaults to false, returning the document before modifications

false

 

sortBy

DocumentLeaving the Site

indicates the DocumentLeaving the Site used to sort the results.

 

remove

boolean

removes the DocumentLeaving the Site specified in the query field. Defaults to false

false

 

upsert

boolean

whether the database should create the element if it does not exist

false

 

bypassDocumentValidation

boolean

lets you update documents that do not meet the validation requirements. Defaults to false

false

 

Returns

Return Java Type Description

DocumentLeaving the Site

a DocumentLeaving the Site that matches the query. If nothing matches, null will be returned


Create index

<mongo:create-index>

Creates a new index

XML Sample

<mongo:create-index config-ref="Mongo_DB__Configuration" collection="myCollection" field="myField" order="DESC"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection where the index will be created

x 

field

StringLeaving the Site

the name of the field which will be indexed

x 

order

IndexOrder

the indexing order

ASC

 


Drop index

<mongo:drop-index>

Drops an existing index

XML Sample

<mongo:drop-index config-ref="Mongo_DB__Configuration" collection="myCollection" index="myIndex"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection where the index is

x 

index

StringLeaving the Site

the name of the index to drop

x 


List indices

<mongo:list-indices>

List existent indices in a collection

XML Sample

<mongo:list-indices config-ref="Mongo_DB__Configuration" collection="myCollection"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

collection

StringLeaving the Site

the name of the collection

x 

Returns

Return Java Type Description

CollectionLeaving the Site<DocumentLeaving the Site>

a collection of DocumentLeaving the Site with indices information


Create file from payload

<mongo:create-file-from-payload>

Creates a new GridFSFile in the database, saving the given content, filename, contentType, and extraData, and answers it.

XML Sample

<mongo:create-file-from-payload config-ref="Mongo_DB__Configuration" filename="#[variable:filename]" metadata-ref="myDbObject"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

payload

ObjectLeaving the Site

the mandatory content of the new gridfs file. It may be a java.io.File, a byte[] or an InputStream.

#[payload]

 

filename

StringLeaving the Site

the mandatory name of new file.

x 

metadata

DocumentLeaving the Site

the optional DocumentLeaving the Site metadata of the new content type

 

Returns

Return Java Type Description

GridFSFileLeaving the Site

the new GridFSFile GridFSFileLeaving the Site


Find files

<mongo:find-files>

Lists all the files that match the given query

XML Sample

<mongo:find-files config-ref="Mongo_DB__Configuration" query-ref="myDbObject" />
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

query

DocumentLeaving the Site

a DocumentLeaving the Site query

#[payload]

 

Returns

Return Java Type Description

IterableLeaving the Site<GridFSFileLeaving the Site>

a GridFSFileLeaving the Site files iterable


Find one file

<mongo:find-one-file>

Answers the first file that matches the given query. If no object matches it, a MongoException is thrown.

XML Sample

<mongo:find-one-file config-ref="Mongo_DB__Configuration" query-ref="myDbObject" />
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

query

DocumentLeaving the Site

the DocumentLeaving the Site mandatory query

#[payload]

 

Returns

Return Java Type Description

GridFSFileLeaving the Site

a GridFSFileLeaving the Site


Get file content

<mongo:get-file-content>

Answers an inputstream to the contents of the first file that matches the given query. If no object matches it, a MongoException is thrown.

XML Sample

<mongo:get-file-content config-ref="Mongo_DB__Configuration" query-ref="myDbObject" />
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

fileId

BsonObjectIdLeaving the Site

the BsonObjectId of the file to be deleted

#[payload]

 

Returns

Return Java Type Description

InputStreamLeaving the Site

an InputStream to the file contents


List files

<mongo:list-files>

Lists all the files that match the given query, sorting them by filename. If no query is specified, all files are listed.

XML Sample

<mongo:list-files config-ref="Mongo_DB__Configuration" query-ref="myDbObject"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

query

DocumentLeaving the Site

the DocumentLeaving the Site optional query

#[payload]

 

Returns

Return Java Type Description

IterableLeaving the Site<GridFSFileLeaving the Site>

an iterable of GridFSFileLeaving the Site


Remove files

<mongo:remove-files>

Removes the file that matches the given file id. If no file id is specified, all files are removed

XML Sample

<mongo:remove-files config-ref="Mongo_DB__Configuration" query-ref="myDbObject"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

fileId

BsonObjectIdLeaving the Site

the BsonObjectId of the file to be deleted

#[payload]

 


Execute command

<mongo:execute-command>

Executes a command on the database

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

commandName

StringLeaving the Site

The command to execute on the database

x 

commandValue

StringLeaving the Site

The value for the command

 

Returns

Return Java Type Description

DocumentLeaving the Site

The result of the command


Dump

<mongo:dump>

Executes a dump of the database to the specified output directory. If no output directory is provided then the default /dump directory is used.

XML Sample

<mongo:dump config-ref="Mongo_DB__Configuration" oplog="true"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

outputDirectory

StringLeaving the Site

output directory path, if no output directory is provided the default /dump directory is assumed

dump

 

outputName

StringLeaving the Site

output file name, if it's not specified the database name is used

 

zip

boolean

whether to zip the created dump file or not

false

 

oplog

boolean

point in time backup (requires an oplog)

false

 

threads

int

amount of threads to execute the dump

5

 


Incremental dump

<mongo:incremental-dump>

Executes an incremental dump of the database

XML Sample

<mongo:incremental-dump config-ref="Mongo_DB__Configuration" />
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

outputDirectory

StringLeaving the Site

output directory path, if no output directory is provided the default /dump directory is assumed

dump

 

incrementalTimestampFile

StringLeaving the Site

file that keeps track of the last timestamp processed, if no file is provided one is created on the output directory

 


Restore

<mongo:restore>

Takes the output from the dump and restores it. Indexes will be created on a restore. It only does inserts with the data to restore, if existing data is there, it will not be replaced.

XML Sample

<mongo:restore config-ref="Mongo_DB__Configuration" inputPath="dump/test.zip" oplogReplay="true"/>
xml

Attributes

Name Java Type Description Default Value Required

config-ref

StringLeaving the Site

Specify which config to use

x 

inputPath

StringLeaving the Site

input path to the dump files, it can be a directory, a zip file or just a bson file

dump

 

drop

boolean

whether to drop existing collections before restore

false

 

oplogReplay

boolean

replay oplog for point-in-time restore

false

 

View on GitHub