Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

On this Page

Table of Contents
maxLevel2
excludeOlder Versions|Additional Resources|Related Links|Related Information

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 Task Pipelines.


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:


InputThis Snap has at most one document input view. If the input view is defined, then values will be used to evaluate the expression in the query condition.
OutputThis Snap has exactly one document output view.
ErrorThis Snap has at most one document error view and produces zero or more documents in the view.


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.

Example: assets

Default value: [None]


Collection name



Required. The MongoDB collection name to execute the find on.

Exampleusers

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.

Code Block
{"id": {$lte: $id}}

 or

Code Block
'{"id": {$lte:' + $id + '}}'


Note

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:

  • 1 or true to include the field
  • 0 or false to exclude the field

Example: {age:0, status:0}

Default value: N/A


Info

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.

Example: {age: = -1}

Default value: N/A

Batch Size


Required. This property limits the number of documents returned in a batch. More can be read here. 
The definition of this property is different from the same property in other DB Snaps.
Assume Batch size is n,

  • if n > 1, get all documents in the collection that match (returns n documents at a time, or as many that can fit in the batch buffer)
  • if n = 1, get only one document in the collection that matches
  • if n = 0, get all documents in the collection that match (returns as many documents that can fit in the batch buffer at a time)
  • if n < 0, get n documents in the collection that match (e.g. if n = -10, get only 10 documents that match)

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.

Example: 0

Default value: 0 

Offset

The starting document for the query. The result set starts from this document.

Example: 100

Default value: N/A

Limit

The number of documents the query must return.

Example: 20

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.

Example:  -7

Default value: 0 


Minutes Offset


The minutes to use for the time zone offset in the date returned by MongoDB.

Example: 1

Default value: 0

Group result

Select to group the output result in a single array.


Note

When Group result is checked, the documents will now be grouped inside an array instead of individual documents.


Default value: Not selected.

Pass through

If selected, the input document will be passed through to the output view under the key 'original'.

Default value: Selected

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: Not selected


Multiexcerpt include macro
nameSnap Execution
pageAnaplan Read


Multiexcerpt include macro
nameSnap_Execution_Introduced
pageAnaplan Read

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:

  1. 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:
  2. 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.
  3. Enter the following query in the Query Condition field of the Snap settings:

    Code Block
    languagesql
    "{\"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:

Insert excerpt
MongoDB Snap Pack
MongoDB Snap Pack
nopaneltrue