MongoDB - Find
On this Page
Snap type: | Read | |||||||
---|---|---|---|---|---|---|---|---|
Description: | This Snap executes a MongoDB find command and outputs the results as documents. | |||||||
Prerequisites: | [None] | |||||||
Support and limitations: | Works in Ultra Tasks. | |||||||
Account: | This Snap uses account references created on the Accounts page of SnapLogic Manager to handle access to this endpoint. See MongoDB Account for information on setting up this type of account. | |||||||
Views: |
| |||||||
Settings | ||||||||
Label | Required. The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline. | |||||||
Database name | The database that the collection is defined in. If not specified, then the MongoDB account database will be used. Default value: None | |||||||
Collection name | Required. The MongoDB collection name to execute the find on. Default value: None | |||||||
Query Condition | The query condition represents the find query parameter. It is an expression that evaluates to an object or JSON string. If no query condition is defined, then all records of the collection will be retrieved. When the expression evaluates to an object, only strict mode is supported. When the expression evaluates to a JSON string, both strict mode and mongo shell mode are supported. More information about MongoDB Extended JSON can be found here. Example: (with '=' button pressed/expression enabled) $id represents an integer in this example. {"id": {$lte: $id}} or '{"id": {$lte:' + $id + '}}' To support date/time strings and to correctly parse dates, the current version of the MongoDB requires a timezone. Example: 2013-08-29T17:56:44.161<Z>, where "Z" is the time offset. Default value: [None] | |||||||
Projection Condition | Specifies which fields must be returned in the matching documents. You can include or exclude fields. You can use the following values:
Default value: N/A Example: {age:0, status:0} A Projection Condition cannot contain both include and exclude specifications. | |||||||
Sort Condition | Orders the documents in the result set. To use multiple sort orders, enter comma-separated sort conditions. Default value: N/A | |||||||
Batch Size | Required. This property limits the number of documents returned in a batch. More can be read here.
In MongoDB 3.4, the batch buffer size is 16MB. In previous versions, the batch buffer size is 4MB. The initial batch will always return a maximum of 101 documents. More can be read here. Default value: 0 | |||||||
Offset | The starting document for the query. The result set starts from this document. Default value: N/A | |||||||
Limit | The number of documents the query must return. Default value: N/A | |||||||
Timezone Offset | ||||||||
Hours Offset | The hours to offset for timezone. MongoDB returns dates in UTC timezone. If another timezone is desired, then an hours offset can be used. If a negative value is used for the hours, then the timezone offset will be in the format -7:00. Default value: 0 | |||||||
Minutes Offset | The minutes to use for the time zone offset in the date returned by MongoDB. Default value: 0 | |||||||
Group result | Select to group the output result in a single array. When Group result is checked, the documents will now be grouped inside an array instead of individual documents. Default value: Deselected | |||||||
Pass through | If selected, the input document will be passed through to the output view under the key 'original'. Default value: Selected | |||||||
Number of retries | Specify the maximum number of attempts to be made to receive a response. The request is terminated if the attempts do not result in a response.
Default Value: 0 | |||||||
Retry interval (seconds) | Specify the time interval between two retry requests. Default Value: 1 | |||||||
Ignore empty result | If selected, no document will be written to the output view when the FIND operation does not produce any result. If this property is not selected and the Pass through property is selected, the input document will be passed through to the output view. Default value: Deselected | |||||||
Snap Execution | Select one of the following three modes in which the Snap executes:
Default value: Validate & Execute |
Troubleshooting
Running queries using a UUID
The current version of the MongoDB driver for Java does not correctly handle queries with UUIDs and as a result, such queries fail. However, you can use the latest version of the MongoDB driver and pass queries with UUIDs.
To run a query using UUIDs, perform the following:
- As the current MongoDB JAR does not support UUIDs in a query, you must use the latest version of the MongoDB driver. Navigate to your MongoDB account settings and select the latest available JAR:
- The new versions of the MongoDB driver do not support date/time strings without timezones. To correctly parse dates, enter a timezone in the Snap Time Zone Offset settings. For example, 2013-08-29T17:56:44.161<Z>, where "Z" is the time offset.
Enter the following query in the Query Condition field of the Snap settings:
"{\"user_id\": new BinData(3,\""+ Base64.encode(Uint8Array.of(...$user_id.replaceAll('-', '').match(/(\w\w)/g).map(x => parseInt(x, 16)))) + "\")}"
Example
In this example, we shall search the documents from a collection using the MongoDB Snap and write them to a binary input view using the JSON Formatter Snap and the File Writer Snap respectively.
The MongoDB Find Snap searches the documents from the Collection Name, mongotable with the Query Condition as '{num:1}' and a default Batch Size 0. This will retrieve all the documents satisfying the query conditions.
Below is the output preview from the MongoDB Find Snap retrieving all the documents:
We shall write the documents to a binary output view using the JSON Formatter and File Writer Snaps respectively.
Successful Execution of the pipeline displays the below output preview:
Snap Pack History
Have feedback? Email documentation@snaplogic.com | Ask a question in the SnapLogic Community
© 2017-2024 SnapLogic, Inc.