MongoDB is a document database and has support for timeseries collections, which can be used to consume Golioth events in a simple, trusted, and scalable way. Golioth's Output Stream for MongoDB Cloud allows you to transform Golioth events into MongoDB's native BSON document and ingest them in your MongoDB instance.
MongoDB Specific Attributes
For each Output Stream type, there is a set of specified attributes. Here are the ones for MongoDB:
|Name||string||✅||Name to identify the Output Stream|
|Event Type Filter||string||✅||Select |
|Connection String||string||✅||Connection string containing username and password|
|Database||string||✅||Name of the MongoDB database|
|Collection||string||✅||Name of the MongoDB collection|
|Timefield||string||✅||Name to use for the timefield in the BSON document (e.g. "timestamp")|
|Metafield||string||✅||Name to use for the metafield in the BSON document (e.g. "metadata")|
To use this integration, you need to:
- Have a MongoDB instance (either a standalone instance or in Atlas, Mongo's managed service)
- Create a MongoDB user that has a username and password
- Create a timeseries collection in your MongoDB database
- (Optional) Add Golioth's IP address to your Atlas IP Access List
- Create an instance of the MongoDB Output Stream in your Golioth account
Setup the MongoDB Output Stream
1. Setup a MongoDB deployment
If you're using MongoDB Atlas, see the Getting Started with Atlas tutorial.
If you're using a local MongoDB installation, see the Install MongoDB tutorial.
2. Create a MongoDB database user
If you are using MongoDB Atlas, see Create a Database User for Your Cluster.
3. Create a timeseries collection
To use the MongoDB timeseries outputstream you must create a timeseries collection in your MongoDB database.
Creating the timeseries collection from mongosh
You can connect to your MongoDB database using the monogsh command, and then from there you can create your timeseries collection. For example:
Creating the timeseries collection from Atlas
You can create your timeseries collection from the Atlas console.
From the collections pages, click the
plus sign next to the database name.
Next, you will see the
Create Collection form.
Collection name field, give your collection a name (e.g.
Then, in the
Additional Preferences dropdown, select
Time Series Collection.
Provide names for the
metaField form fields. You will use
these fields when you create the outputstream in the Golioth console.
Finally, click the
4. Get the MongoDB connection string
If you're using a local deployment, the connection string will be of the form
mongodb://<username>:<password>@localhost:[port] where the port is 27017 by
If you're using an Atlas deployment, you can get the connection string from the
Atlas console. From the
Database Deployments screen, click the
Access your data through tools, select
Finally, copy the connection string without a trailing slash.
5. Add Golioth IP Address to Access List (MongoDB Atlas)
In order for Golioth to send your events to your MongoDB timeseries collection, you will need to add Golioth's IP address to your MongoDB Atlas IP Access List.
From the left-hand navigation in the Atlas console, click the
Network Access screen, click the
ADD IP ADDRESS button.
18.104.22.168/32 to the
Access List Entry field, and optionally add a
comment, e.g. "Golioth". Then click
6. Create an MongoDB Output Stream in the Golioth console
Select an Output Stream Type page, select
Create a new Output Stream form, enter the following:
- Name: The name you want to give to your Output Stream
- Event Type Filter: select
DEVICE_STREAM_TYPEfrom the list of types (the MongoDB Output Stream is currently limited to stream events only)
- Connection String: Paste the
Connection Stringyou copied for your MongoDB cluster
- Database: the name of an existing MongoDB database where you want to send your events
- Collection: The time series collection to store your events
- Timefield: the name of the field containing the date in your time series document
- Metafield: the name of the field containing metadata in your timeseries document (your deviceId and projectId will be populated here)
Golioth Output Streams utilize the Cloud Events format. Therefore, it is necessary to transform events from the CloudEvents format into a MongoDB BSON (Binary JSON) document.
Here is an example of a CloudEvent on the Golioth platform:
We transform the above CloudEvent to the following BSON document: