MongoDB
Prerequisites
Setup
LogicLoop supports non-relational databases like MongoDB as a datasource.
You'll first connect your datasource 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.
Write your MongoDB query as a valid JSON object. LogicLoop will convert it into either a db.collection.find()
call or a db.collection.aggregate()
call. Here’s how your JSON object is mapped and sent to MongoDB:
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...
...into this call to MongoDB:
Here are some other examples of MongoDB queries you can write with LogicLoop.
Count
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:
MongoDB Extended JSON Support
We support MongoDB Extended JSON along with our own extension - $humanTime
:
It accepts a human-readable string like the above (“3 years ago”, “yesterday”, etc) or timestamps.
The $humanTime
function is also needed when using Query Parameters of type Date or Date/Time with MongoDB.
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.
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.
In MongoDB, the in-memory sorting have a limit of 100M, to perform a large sort, you need enable allowDiskUse
option to write data to a temporary files for sorting.
To enable the allowDiskUse
option, just add the option to your query:
Last updated