Skip to main content

MongoDB

This guide contains information to set up a MongoDB Sink in Vanus Connect.

Introduction

MongoDB is a popular open-source NoSQL document database that stores data in a flexible, JSON-like format.

The MongoDB Sink connector let you insert events into a mongoDB database automatically.

Prerequisites

Before forwarding events to MongoDB, you must have:

Getting Started

Step 1: Setting up your MongoDB Cluster

  1. Log in to your MongoDB Account

  2. Click on Build a Database①.

mongodb-sink-1

  1. Select the MO② template for a free deployment, pick your preferred cloud Provider③ and Region④, provide a Name⑤ for your cluster and then click Create⑥.

mongodb-sink-2

  1. Choose Username and Password⑦ as your authentication method, enter your Username⑧ and Password⑨, and then click Create User⑩.

mongodb-sink-3

  1. Choose My Local Environment⑪ to connect to your MongoDB database from your local machine. Click on Add My Current IP Address⑫ and then hit the Add Entry⑬ button to grant your device access to your MongoDB cluster. Then, click Finish and Close⑭.

mongodb-sink-4

  1. Click on Go to Databases⑮ to access your database page.

mongodb-sink-5

Step 2: MongoDB Cluster Connection Settings

  1. Click on the Connect① button.

mongodb-sink-6

  1. Choose the method you'd like to use for connecting to your database. In our case, we selected the Shell②.

mongodb-sink-7

  1. Select your operating system③, Download mongosh④, and open the How to link in a new tab to get step-by-step instructions on how to add your mongosh directory to your $PATH variable.

mongodb-sink-8

  1. After completing the Mongosh set-up, return to the Atlas page and Copy⑥ the connection string provided.

mongodb-sink-9

  1. Paste the command⑦ in your terminal, and you will be prompted to enter the password you set for database authentication.

mongodb-sink-10

  1. Run the use <databasename> command to create a database.

mongodb-sink-11

  1. Run the command below to create a collection and insert values in it.
db.<collectionname>.insertMany([
{ name: "John", age: 30 },
{ name: "Jane", age: 25 },
{ name: "Bob", age: 35 }
]);
note

Substitute <databasename> and <collectionname> with the names you prefer for your database and collection.

  1. Run the db.your_collection_name.find() command to confirm that your collection has been created with its inserted values.

mongodb-sink-12

Step 3: Set up MongoDB Sink in Vanus Connect

  1. Navigate to the Vanus Cloud platform and fill in the following credentials.

mongodb-sink-13

  • Connection Uri: The URI to connect MongoDB, view Connection String URI Format for more details.
  • Username: MongoDB username.
  • Password: MongoDB user's password.
  • Database: This is the database name, not to be confused with the cluster name.
  • Collection: Collection Name

Step 4: Personalize Event Structure

note

This is a general instruction on how to personalize your event structure. You can structure your events to suit your specific requirements and create connections for different scenarios.

  1. Click on Display sample events① for reference and click on Add More② to add events.

mongodb-sink-14

  1. Input key③ and search for the corresponding value④ for the event you want.

mongodb-sink-15

  1. You can fill in as many key-value pairs⑤ as you wish to receive.

mongodb-sink-16

  1. Click Submit⑥ to finish the configuration process.

mongodb-sink-17

Custom Connection

Create your template following the structure of your database, an example:


{
"inserts": [
{
"scenario": "quick-start"
}
]
}