MongoDBWriter

Available in Community Designer

Short Description
Ports
Metadata
MongoDBWriter Attributes
Details
Examples
See also

Short Description

MongoDBWriter stores, removes or updates data in the MongoDB™ database using the Java driver. [1]

MongoDBWriter can manipulate with documents in a MongoDB collection. New documents can be inserted, existing documents can be updated or removed.

Component Data output Input ports Output ports Transformation Transf. required Java CTL Auto-propagated metadata
MongoDBWriterdatabase10-2
yes
yes
no
yes
yes

Icon

Ports

Port typeNumberRequiredDescriptionMetadata
Input0
yes
Input data records to be mapped to component attributes.any
Output0
no
Resultsany
1
no
Errorsany

Metadata

MongoDBWriter does not propagate metadata.

This component has metadata templates. The templates are described in the documentation of MongoDBReader in section Metadata.

MongoDBWriter Attributes

AttributeReqDescriptionPossible values
Basic
Connection
yes
ID of the MongoDB connection to be used. 
Collection nameyes  [ 1] The name of the target collection.  
Operation The operation to be performed. MongoDBWriter can perform insert, remove, save, and three variants of the update operation (update, update_multi, upsert). insert (default) | remove | save | update | update_multi | upsert
Query 

A query that selects a subset of documents from a collection. The selection criteria may contain query operators.

Only used by the remove, update, update_multi and upsert operations.

BSON document
New valueyes  [ 1]

Specifies the document to be stored in the database.

For the update, update_multi and upsert operations, update operators may be used.

The attribute is required for all but the remove operation.

BSON document
Input mapping
yes
Defines mapping of input records to component attributes. 
Output mapping[ 2]Defines mapping of results to standard output port. 
Error mapping[ 2]Defines mapping of errors to error output port. 
Advanced
Stop processing on fail  By default, a failure causes the component to skip all subsequent operations and send the information about skipped executions to the error output port. This behaviour can be turned off by this attribute. true (default) | false
Insert batch size 

Number of records that can be sent to database in one batch insert. Batch mode is off by default.

Note that although the bulk insert operation may significantly increase performance, it can be dangerous, as it is not atomic and the component does not provide any information about which documents were successfully inserted and which were not.

1 (default) | 2-N
Field pattern 

Specifies the format of placeholders that can be used within the Query and New value attributes. The value of the attribute must contain "field" as a substring, e.g. "<field>", "#{field}", etc.

During the execution, each placeholder is replaced using simple string substitution with the value of the respective input field, e.g. the string "@{name}" will be replaced with the value of the input field called "name" (assuming the default format of the placeholders).

@{field} (default) | any string containing "field" as a substring

[ 1] The attribute is required, unless specified in the Input mapping.

[ 2]  Required if the corresponding edge is connected.

Details

Operations
Mapping

Operations

insert

Adds the value of the New value attribute as a new document to the target Collection. If the document does not contain the _id field, a generated one will be added.

See also db.collection.insert().

remove

Removes objects that match the Query from the Collection.

See also db.collection.remove().

save

Similar to insert, adds the document specified as the New value attribute to the Collection or replaces an existing document with the same _id.

See also db.collection.save().

update

Updates at most one document that matches the Query, with the values specified in the New value attribute, which may contain update operators.

See also db.collection.update().

update_multi

Updates multiple documents matching the Query using update operators specified in the New value attribute.

See also db.collection.update() - multi.

upsert

If no existing document matches the Query, inserts a new document into the Collection, otherwise performs an update. The New value attribute may contain update operators.

See also db.collection.update() - upsert.

Mapping

Editing any of the Input, Output or Error mapping opens the Transform Editor.

Input mapping

The editor allows you to override selected attributes of the component with the values of the input fields.

Field NameAttributeTypePossible values
collectionCollectionstring 
queryQuerystring 
newValueProjectionstring 
Output mapping

The editor allows you to map the results and the input data to the output port.

If output mapping is empty, fields of input record and result record are mapped to output by name.

Field NameTypeDescription
numAffectedintegerThe number of affected documents, only set by the update, update_multi and upsert operations.
objectIdstringThe object ID of the document. Only set by the insert and save operations. Not populated in the bulk insert mode.
Error mapping

The editor allows you to map the errors and the input data to the error port.

If error mapping is empty, fields of input record and result record are mapped to output by name.

Field NameTypeDescription
errorMessagestringThe error message.
stackTracestringThe stack trace of the error.

Notes and Limitations

MongoDBWriter does not write maps and lists. It converts maps and lists to string and writes the string.

Examples

Writing records to MongoDB

Insert records (productID, productName, description) to collection newProducts.

Solution

Create MongoDB Connection to target database.

Set up the following attributes:

AttributeValue
ConnectionMyMongoDBConnection
Collection namenewProducts
OperationInsert
New value{ productID : @{productID}, productName : "@{productName}", description: "@{description}"}

See also

MongoDBReader
MongoDBExecute
Common Properties of Components
Specific Attribute Types
Common Properties of Writers
Writers Comparison
MongoDB connection


[1]  MongoDB is a trademark of 10gen, Inc.