MongoDB Collection Source Example

1. Example Data

The following is an example of data we want to sync out of MongoDB.

test> db.Articles.find()
[
  {
    _id: ObjectId("63d812afd755fcdeed234402"),
    Name: 'Shirt',
    Price: 19.95,
    Details: { Color: 'Red', Size: 'Medium' },
    Stock: 12
  },
  {
    _id: ObjectId("63d8137bd755fcdeed234403"),
    Name: 'Shirt',
    Price: 9.95,
    Details: { Color: 'White', Size: 'Small' },
    Stock: 61
  }
]

2. XML Example

This example XML uses the following values:

ValueDescriptionExample

connectionString

The connections string for your source

"87E4lvPf83gLK8eKapH6Y0YqIFSNbFlq62uN9487"

Database

The name of your MongoDB database

"test"

Collection

The name of your MongoDB collection.

"Article"

Type

The method used to retrieve your data.

"find"

Query

A query for retrieving your data.

This example query returns data where the price is less than 10$.

"{ "Price": { "$lt": 10 } }"

Projection

A projection for flattening your source document.

"{
    "Name": 1,
    "Price": 1,
    "Color": "Details.Color",
    "Size": "Details.Size",
    "Stock": 1,
    "Details": 1
}"

Column Name

The name(s) of your source column(s)

"id" "name" "price" "colour" "size" "stock" "$" (This is used to retrieve the full document.) "Details" (This is imported both as set of fields (flattened from the projection) and as a JSON.)

dataType

The data type of your source column

"Text" "Text" "Number" "Text" "Text" "Number" "Text" "Text"

isMandatory

Whether the column is mandatory or not

"false"

validateData

Whether the column data needs to be validated or not

"false"

1.1 XML Example

<BatchDataSyncConfig name=""MongoDB Data Source Example"" version=""1.0.0""
    xmlns=""http://www.cinchy.co"">
    <MongoCollectionDataSource connectionString=""AI+FJVIMO1HP/CkZ5yphXeJ01wjH/4ilJ8xAIPPDyxvYq0oiYnVBQrzaq2Cp5942poeDdOp"" database=""test"" collection=""Articles"" type=""find"" query=""{ &quot;Price&quot;: { &quot;$lt&quot;: 10 } }"" projection=""{
    &quot;Name&quot;: 1,
    &quot;Price&quot;: 1,
    &quot;Color&quot;: &quot;Details.Color&quot;,
    &quot;Size&quot;: &quot;Details.Size&quot;,
    &quot;Stock&quot;: 1,
    &quot;Details&quot;: 1
}"">
        <Schema>
            <Column name=""_id"" dataType=""Text"" trimWhitespace=""true"" isMandatory=""false"" validateData=""false""/>
            <Column name=""Name"" dataType=""Text"" trimWhitespace=""true"" isMandatory=""false"" validateData=""false""/>
            <Column name=""Price"" dataType=""Number"" isMandatory=""false"" validateData=""false""/>
            <Column name=""Color"" dataType=""Text"" trimWhitespace=""true"" isMandatory=""false"" validateData=""false""/>
            <Column name=""Size"" dataType=""Text"" trimWhitespace=""true"" isMandatory=""false"" validateData=""false""/>
            <Column name=""Stock"" dataType=""Number"" isMandatory=""false"" validateData=""false""/>
            <Column name=""$"" dataType=""Text"" trimWhitespace=""true"" isMandatory=""false"" validateData=""false""/>
            <Column name=""Details"" dataType=""Text"" trimWhitespace=""true"" isMandatory=""false"" validateData=""false""/>
        </Schema>
    </MongoCollectionDataSource>

Last updated