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
Connection String
<mongo:config-connection-string>
Connection Management
Configuration
<mongo:config>
Connection Management
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
name |
The name of this configuration. With this name can be later referenced. |
x |
||
username |
the username to use for authentication. |
|
||
password |
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 |
Name of the database |
x |
||
host |
A list of MongoDB instance, with the format
Example: 127.0.0.1:27017, 192.168.1.2:27017 |
localhost:27017 |
|
|
connectionsPerHost |
The number of connections allowed per host (the pool size, per host) |
|
||
threadsAllowedToBlockForConnectionMultiplier |
Multiplier for connectionsPerHost for # of threads that can block. |
|
||
maxWaitTime |
The max wait time for a blocking thread for a connection from the pool in ms. |
|
||
connectTimeout |
The connection timeout in milliseconds; this is for establishing the socket connections (open). 0 is default and infinite. |
30000 |
|
|
socketTimeout |
The socket timeout. 0 is default and infinite. |
|
||
ssl |
boolean |
This is for enabling an SSL connection. It is disabled by default. |
false |
|
authenticationDatabase |
|
|||
retryWrites |
boolean |
false |
|
|
iterableBehaviour |
boolean |
This flag gives the possibility to switch between both implementations of receiving either an Iterable object (v4.4.0 and older versions) or an ArrayList (v4.4.1 and newer versions) as the result object of findDocuments. The default behavior is ArrayList. |
false |
|
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
newUsername |
Name of the user |
x |
||
newPassword |
Password that will be used for authentication |
x |
Drop database
<mongo:drop-database>
Drop the current database
XML Sample
<mongo:drop-database config-ref="Mongo_DB__Configuration"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
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"/>
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the name of the collection to create |
x |
||
capped |
boolean |
if the collection will be capped |
false |
|
maxObjects |
the maximum number of documents the new collection is able to contain |
|
||
size |
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>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the name of the collection where to insert the given document. |
x |
||
document |
a Document instance. |
#[payload] |
|
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>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the name of the collection where to insert the given document. |
x |
||
documents |
#[payload] |
|
||
ordered |
boolean |
indicates if the list of write operations is ordered or unordered. By default, if 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 |
|
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>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the name of the collection to update |
x |
||
query |
the Document query object used to detect the element to update. |
|
||
element |
the Document 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 |
|
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>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the name of the collection to update |
x |
||
function |
the function used to execute the update |
x |
||
query |
the Document query document used to detect the element to update. |
|
||
element |
the Document 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 |
|
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 |
Specify which config to use |
x |
||
collection |
the name of the collection to update |
x |
||
query |
the Document query document used to detect the element to update |
|
||
functions |
the Document of functions used to execute the update. e.g. %3c$set,{"key":123}%3e |
#[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 |
|
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>
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>
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the name of the collection to map and reduce |
x |
||
mapFunction |
a JavaScript encoded mapping function |
x |
||
reduceFunction |
a JavaScript encoded reducing function |
x |
||
outputCollection |
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. |
|
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the target collection |
x |
||
query |
the optional Document 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>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the target collection |
x |
||
query |
the optional Document query document. If unspecified, all documents are returned. |
#[payload] |
|
|
fields |
alternative way of passing fields as a literal List |
|
||
numToSkip |
number of documents skip (offset) |
|
||
limit |
limit of documents to return |
|
||
sortBy |
indicates the Document used to sort the results |
|
||
returnId |
boolean |
indicates if the _id field should be returned. Default value is true. |
true |
|
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>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the target collection |
x |
||
query |
the mandatory Document query document that the returned object matches. |
#[payload] |
|
|
fields |
alternative way of passing fields as a literal List |
|
||
failOnNotFound |
Flag to specify if an exception will be thrown when no object is found. For backward compatibility the default value is true. |
true |
|
|
returnId |
boolean |
indicates if the _id field should be returned. Default value is true. |
true |
|
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 |
Specify which config to use |
x |
||
collection |
the target collection |
x |
||
query |
the Document query that the returned object matches. |
|
||
element |
the Document mandatory object that will replace that one which matches the query |
#[payload] |
|
|
fields |
alternative way of passing fields as a literal List |
|
||
returnNewDocument |
Flag to specify if the returning Document should be the updated document instead of the original. Defaults to false, returning the document before modifications |
false |
|
|
sortBy |
indicates the Document used to sort the results. |
|
||
remove |
boolean |
removes the Document 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 |
|
returnId |
boolean |
indicates if the _id field should be returned. Default value is true. |
true |
|
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the name of the collection where the index will be created |
x |
||
field |
the name of the field which will be indexed |
x |
||
order |
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"/>
List indices
<mongo:list-indices>
List existent indices in a collection
XML Sample
<mongo:list-indices config-ref="Mongo_DB__Configuration" collection="myCollection"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
collection |
the name of the collection |
x |
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
payload |
the mandatory content of the new gridfs file. It may be a java.io.File, a byte[] or an InputStream. |
#[payload] |
|
|
filename |
the mandatory name of new file. |
x |
||
metadata |
the optional Document metadata of the new content type |
|
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" />
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
query |
a Document query |
#[payload] |
|
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" />
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
query |
the Document mandatory query |
#[payload] |
|
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" />
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
fileId |
the BsonObjectId of the file to be deleted |
#[payload] |
|
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
query |
the Document optional query |
#[payload] |
|
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
fileId |
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 |
Specify which config to use |
x |
||
commandName |
The command to execute on the database. If the whole command is sent in the commandValue parameter, set commandName to blank. |
|
||
commandValue |
The value for the command, or the whole command itself, as a document. |
|
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
outputDirectory |
output directory path, if no output directory is provided the default /dump directory is assumed |
dump |
|
|
outputName |
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" />
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
outputDirectory |
output directory path, if no output directory is provided the default /dump directory is assumed |
dump |
|
|
incrementalTimestampFile |
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"/>
Attributes
Name | Java Type | Description | Default Value | Required |
---|---|---|---|---|
config-ref |
Specify which config to use |
x |
||
inputPath |
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 |
|