Short Description |
Ports |
Metadata |
MongoDBReader Attributes |
Details |
Examples |
See also |
MongoDBReader reads data from the MongoDB™ database using the Java driver. [1]
MongoDBReader reads data from the MongoDB database
using the find
database command.
It can also perform the aggregate
,
count
and distinct
commands.
Component | Data source | Input ports | Output ports | Each to all outputs | Different to different outputs | Transformation | Transf. req. | Java | CTL | Auto-propagated metadata |
---|---|---|---|---|---|---|---|---|---|---|
MongoDBReader | database | 0-1 | 1-2 |
Port type | Number | Required | Description | Metadata |
---|---|---|---|---|
Input | 0 | Input data records to be mapped to component attributes. | any | |
Output | 0 | Results | any | |
1 | Errors | any |
MongoDBReader does not propagate metadata.
This component has metadata templates available. See details on Metadata Templates.
Table 53.8. MongoDBReader_Attributes
Field number | Field name | Data type | Description |
---|---|---|---|
1 | collection | string | |
2 | query | string | |
3 | projection | string | |
4 | orderBy | string | |
5 | skip | integer | |
6 | limit | integer |
Table 53.9. MongoDBReader_Result
Field number | Field name | Data type | Description |
---|---|---|---|
1 | stringValue | string | |
2 | jsonObject | [string,string] | |
3 | count | long |
Table 53.10. MongoDBReader_Error
Field number | Field name | Data type | Description |
---|---|---|---|
1 | errorMessage | string | |
2 | stackTrace | string |
Attribute | Req | Description | Possible values |
---|---|---|---|
Basic | |||
Connection | ID of the MongoDB connection to be used. | ||
Collection name | [ 1] | The name of the source collection. | |
Operation | The operation to be performed. | find (default) | aggregate | count | distinct | |
Query | A query that selects only matching documents from a collection. The selection criteria may contain query operators. To return all documents in a collection, omit this parameter. For the | BSON document | comma-separated list of BSON documents (aggregate only) | |
Projection | Specifies the fields to return using projection operators:
The boolean can take the following include or exclude values:
The Projection cannot contain both include and exclude specifications except for the exclusion of the To return all fields in the matching document, omit this parameter. For the | BSON document | field name (distinct only) | |
Order by | Sorts
the result of the The attribute affects only the | BSON document | |
Skip | Set the starting point of a result of the The attribute affects only the | ||
Limit | Specifies the maximum number of documents
the The attribute affects only the | ||
Input mapping | [ 2] | Defines mapping of input records to component attributes. | |
Output mapping | Defines mapping of results to standard output port. | ||
Error mapping | [ 2] | Defines mapping of errors to error output port. | |
Advanced | |||
Query options | Specifies the query options for the The attribute is ignored by all operations other than | ||
Field pattern | Specifies the format of placeholders that can be used within
the Query, Projection and
Order by attributes.
The value of the attribute must contain " During the execution, each placeholder is replaced using simple string
substitution with the value of the respective input field, e.g.
the string " | @{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. |
By default, MongoDBReader performs the
find()
operation.
It can also be used to execute the aggregate()
,
count()
or distinct()
operations.
The result set elements can be mapped one by one to the first output port using the Output mapping attribute.
Editing any of the Input, Output or Error mapping opens the Transform Editor.
The editor allows you to override selected attributes of the component with the values of the input fields.
Field Name | Attribute | Type | Possible values |
---|---|---|---|
collection | Collection | string | |
query | Query | string | |
projection | Projection | string | |
orderBy | Order by | string | |
skip | Skip | integer | |
limit | Limit | integer |
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 Name | Type | Description |
---|---|---|
stringValue | string | Contains the current element of the result set converted to a string. |
jsonObject | map[string, string] | Conditional. Contains the current result set element, if it is a JSON object. The values of the object are serialized to strings. |
count | long | Only used for the count operation, contains the number of matching documents. |
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 Name | Type | Description |
---|---|---|
errorMessage | string | The error message. |
stackTrace | string | The stack trace of the error. |
In queries you can use extended JSON, e.g.
{_id: {$oid: "53b0e84b72a0ec06118b45fd"}}
Similar format is used for passing long
data type, timestamp, binary data etc.
See http://docs.mongodb.org/manual/reference/mongodb-extended-json/
Let us assume that the documents in the source collection resemble the following:
{ customer : "John", value : 123 }
If executed without any parameter, the find
operation will list all the documents in the source collection.
If the Query attribute is set to { customer: { $in: [ "John", "Jane" ] } }
,
the result set will only contain documents whose "customer" field has the value "John" or "Jane".
If the Projection attribute is set to { customer: 1 }
,
the result set will only contain the "_id" and "customer" fields.
If the Order by attribute is set to { value: 1 }
,
the result set will be sorted by the "value" field in ascending order.
If the Skip attribute is set to 5
,
the first five documents in the result set will be skipped.
If the Limit attribute is set to 20
,
at most 20 documents will be returned.
Consider the following aggregation pipeline:
{ $group : { _id : "$customer", sum : { $sum : "$value" } } }, { $match : { sum : { $gt : 1500 } } }, { $sort : { sum : -1 } }, { $limit : 10 }, { $project : { _id : 0, name : { $toUpper : "$_id" }, total : "$sum" } }
The count
operation can be limited to documents matching the specified Query.
For example, { value : { $gt : 150 } }
will count the number of documents whose "value" field
has a value greater than 150.
The result is returned as the count output field.
We could use the distinct
operation to retrieve the list of names of all the customers
- set the value of the Projection attribute to customer
(without quotes).
Optionally, a Query may be specified to limit the input documents for the
distinct analysis.
You can query for an object having the specific object ID.
{ _id: {"$oid" : "54ca707ceac6b571fb4aa285"}}