Docs
  • LogicLoop Documentation
  • LogicLoop Quickstart
  • Data Sources
    • Connect your data source
      • Deployment options
    • Supported data sources
      • API data (JSON)
      • AWS CloudWatch
      • BigQuery
      • Databricks
      • Google Analytics
      • Google Sheets
      • MongoDB
      • Microsoft SQL Server
      • MySQL
      • Oracle
      • PostgreSQL
      • Snowflake
      • Combine Results
      • LogicLoop Data Source
  • Queries
    • Write a rule
      • More rule options
      • A/B testing rules
      • Version history
      • Query Snippets
    • Visualizations & dashboards
      • Visualizations
      • Dashboards
  • Actions
    • Set up an action
    • Action destinations
      • Email
      • Slack
      • Webhooks & APIs
      • Microsoft Teams
      • Salesforce
      • Zapier
      • PagerDuty
      • Write to Database
      • Chain Rules
      • Google Sheets
      • Bento
    • Templating
  • Case Management
    • Case Management
      • Ticket Generation
      • Case Triage
      • Custom Fields and Attachments
  • AI
    • AI Query Helper
    • Ask AI
  • Teams & Settings
    • Integrations
      • Slack
      • Google Sheets
    • Invite your teammate
    • Groups & Permissions
  • Changelog
  • FAQs
  • Troubleshooting
  • Templates
    • Templates Home
    • Risk & Fraud Rules
    • AML Transaction Monitoring Rules
    • Logistics & Marketplace Ops
    • Customer Success & Growth
    • Systems Observability
    • Data Quality Monitoring
    • Healthcare
    • HTML Email Templates
      • Annual Review
      • Weekly Performance Table
      • Invoice Recap
  • BETA
    • AI SQL API
    • Approving rules
    • Render Data as JSON
    • Case Analytics
    • Python
  • Security & Legal
    • Security
    • AI Security
    • Terms of use
    • Privacy policy
    • Services description
Powered by GitBook
On this page
  • Prerequisites
  • Setup
  • Troubleshooting

Was this helpful?

  1. Data Sources
  2. Supported data sources

MongoDB

PreviousGoogle SheetsNextMicrosoft SQL Server

Last updated 1 year ago

Was this helpful?

Prerequisites

Setup

LogicLoop supports non-relational databases like MongoDB as a datasource.

You'll first and select your MongoDB datasource from the sources dropdown in your query interface. All you need is to enter your Mongo connection string and database name.

MongoDB Token

Where to write in LogicLoop

db

On the data source setup screen

collection

Add a collection key in your query object

query

Add a query key in your query object

projection

Add a fields key in your query object

.sort() method

Add a sort key in your query object

.skip() method

Add a skip key in your query object

.limit() method

Add a limit key in your query object

db.collection.count() method

Use a count key with any value in your query object

The values you use for each key are passed unmodified as as parameters to MongoDB. A sample query looks like this:

So LogicLoop will convert this query object...

{
	"collection": "people",
	"query": {
	    "views": { "$gt": 1000000 }
	}
}

...into this call to MongoDB:

db.my_collection.find({"collection": "people", "query": {"views": {"$gt": 10000000 }}})

Here are some other examples of MongoDB queries you can write with LogicLoop.

Count

{
	"collection": "my_collection",
	"count": true
}

Aggregation

Aggregation uses a syntax similar to the one used in PyMongo. However, to support the correct order of sorting, it uses a regular list for the “$sort” operation:

{
	"collection": "things",
	"aggregate": [{
		"$unwind": "$tags"
	}, {
		"$group": {
			"_id": "$tags",
			"count": {
				"$sum": 1
			}
		}
	}, {
		"$sort": [{
			"name": "count",
			"direction": -1
		}, {
			"name": "_id",
			"direction": -1
		}]
	}]
}

MongoDB Extended JSON Support

{
	"collection": "date_test",
	"query": {
		"lastModified": {
			"$gt": {
				"$humanTime": "3 years ago"
			}
		}
	},
	"limit": 100
}

It accepts a human-readable string like the above (“3 years ago”, “yesterday”, etc) or timestamps.

When using a Date (or Date Range) parameter, wrap it with a $humanTime object: {{param}} becomes {"$humanTime": "{{param}} 00:00"} (the 00:00 suffix is needed only with Date parameters, skip for Date Time parameters).

MongoDB Filtering

You can add filters to Mongo queries by projecting a column with the ‘::filter’ keyword added on to the end.

{
	"collection": "zipcodes",
	"aggregate": [{
		"$project": {
			"_id": "$_id",
			"city": "$city",
			"loc": "$loc",
			"pop": "$pop",
			"state::filter": "$state"
		}
	}]
}

The above example will show a ‘State’ column, and allow you to filter on this column.

Troubleshooting

Sort exceeded memory limit of 104857600 bytes

Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.

To enable the allowDiskUse option, just add the option to your query:

{
  ...
  "allowDiskUse": true
}

Write your MongoDB query as a valid JSON object. LogicLoop will convert it into either a call or a call. Here’s how your JSON object is mapped and sent to MongoDB:

We support along with our own extension - $humanTime:

The $humanTime function is also needed when using of type Date or Date/Time with MongoDB.

In MongoDB, , to perform a large sort, you need enable allowDiskUse option to write data to a temporary files for sorting.

db.collection.find()
db.collection.aggregate()
MongoDB Extended JSON
Query Parameters
the in-memory sorting have a limit of 100M
allows access to LogicLoop
Deployment
admin
connect your datasource