MongoDB
Datafly Signal inserts first-party events as documents into a MongoDB collection — ideal for schema-agnostic NoSQL storage with rich querying, aggregation, and indexing.
Why route MongoDB through Datafly Signal
- The data lands in infrastructure you own. Signal writes to your MongoDB directly from your own deployment. Datafly operates no intermediary and never holds a copy of your event data.
- Client IP and user agent are recorded as event context. Both come from the original visitor request rather than from your server, so geography and device analysis done in the warehouse reflects the actual visitor.
- Presets for Retail and General. The mapping starts from a working configuration for your vertical instead of a blank field map.
- One consent decision governs every destination. MongoDB is gated by the same consent state as the rest of your stack, so a withdrawal applies everywhere at once.
Prerequisites
Before configuring MongoDB in Signal, you need a MongoDB instance (self-hosted or Atlas), a database and collection, and a connection URI.
Set Up a MongoDB Instance
You have two options:
Option A: MongoDB Atlas (Managed)
- Sign up at mongodb.com/cloud/atlas.
- Create a new project and click Build a Cluster.
- Choose a tier:
- M0 (Free) — suitable for development and testing.
- M10+ — production-ready with dedicated resources.
- Select a cloud provider and region.
- Click Create Cluster.
Option B: Self-Hosted MongoDB
- Install MongoDB using the official guide.
- Start the
mongodprocess. - Ensure the server is accessible from your Signal infrastructure.
Configure Network Access (Atlas)
- In Atlas, go to Network Access > Add IP Address.
- Add the IP addresses of your Signal deployment.
- Click Confirm.
Never whitelist 0.0.0.0/0 (allow from anywhere) in production. Restrict access to only your Signal infrastructure IP addresses.
Create a Database User
For Atlas:
- Go to Database Access > Add New Database User.
- Choose Password authentication.
- Enter a Username (e.g.
datafly_signal) and Password. - Under Database User Privileges, select Read and write to any database or restrict to a specific database with
readWriterole. - Click Add User.
For Self-Hosted:
use admin
db.createUser({
user: "datafly_signal",
pwd: "your_secure_password",
roles: [
{ role: "readWrite", db: "datafly_events" }
]
})Get the Connection URI
For Atlas:
- In your cluster, click Connect > Connect your application.
- Select Driver: Node.js (or any driver — the URI format is the same).
- Copy the Connection string (e.g.
mongodb+srv://datafly_signal:password@cluster0.abc123.mongodb.net/datafly_events). - Replace
<password>with the actual password.
For Self-Hosted:
The URI format is: mongodb://datafly_signal:password@hostname:27017/datafly_events
Create a Database and Collection
MongoDB creates databases and collections automatically on first write. However, you can create them explicitly:
use datafly_events
db.createCollection("events")
db.events.createIndex({ "timestamp": -1 })
db.events.createIndex({ "type": 1, "event": 1 })Creating indexes in advance improves query performance. The timestamp descending index is useful for retrieving recent events, and the compound index on type and event optimises filtered queries.
Configuration
| Field | Type | Required | Description |
|---|---|---|---|
uri | secret | Yes | The MongoDB connection string (e.g. mongodb+srv://user:pass@cluster.mongodb.net/dbname). Also accepts connection_uri. |
database | string | Yes | The target database name. |
collection | string | Yes | The target collection name to insert documents into. |
Signal Setup
Quick Setup
- Navigate to Integrations in the sidebar.
- Open the Integration Library tab.
- Find MongoDB or filter by Database.
- Click Install, select a variant if available, and fill in the required fields.
- Click Install Integration to create the integration with a ready-to-use default blueprint.
API Setup
curl -X POST http://localhost:8084/v1/admin/integration-catalog/mongodb/install \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "MongoDB",
"variant": "default",
"config": {
"uri": "mongodb+srv://datafly_signal:your_password@cluster0.abc123.mongodb.net/datafly_events",
"database": "datafly_events",
"collection": "events"
},
"delivery_mode": "server_side"
}'Schema
Each event becomes one BSON document with the canonical envelope as top-level fields:
{
"_id": ObjectId("..."),
"event_id": "...",
"type": "track",
"event": "order_completed",
"anonymous_id": "...",
"user_id": "...",
"timestamp": ISODate("..."),
"received_at": ISODate("..."),
"sent_at": ISODate("..."),
"context": { ... },
"properties": { ... },
"traits": { ... },
"source_id": "...",
"integration_id": "..."
}Add indexes on event_id (unique, for dedupe), timestamp (descending, for recent-event queries), and (type, event) (compound, for filtered queries).
Consent
MongoDB is a first-party destination under your control. The default blueprint forwards all events. Apply consent filtering via pipeline transforms or via aggregation $match stages on context.consent if your governance requires it.
Testing
- Enable the integration in Signal and trigger a test event on your website.
- Connect to your MongoDB instance and query the collection:
use datafly_events
db.events.find().sort({ timestamp: -1 }).limit(10)- Or in Atlas, use the Browse Collections interface to view documents.
- In Signal, check the Live Events view to confirm delivery status shows as successful.
Troubleshooting
| Problem | Solution |
|---|---|
| Events not appearing in the collection | Verify the connection URI, database, and collection name are correct. |
Authentication failed | The username or password in the connection URI is incorrect. Verify the database user credentials. |
| Connection timeout | Check that Signal’s IP addresses are whitelisted in Atlas Network Access (or firewall rules for self-hosted). Verify DNS resolution. |
not authorized on database | The database user lacks readWrite permission on the database. Update the user’s roles in Database Access. |
MongoServerSelectionError | The connection string may be incorrect or the cluster is unreachable. Check the URI format and network connectivity. |
| Document too large | MongoDB documents cannot exceed 16 MB. Check the event payload size. |
| Write concern errors | If using replica sets, verify the write concern configuration. Default write concern (w:1) is sufficient for most use cases. |
Visit MongoDB documentation for full query reference, aggregation pipeline guides, and Atlas management.