Docs
Search…
MongoDB
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:
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...
1
{
2
"collection": "people",
3
"query": {
4
"views": { "$gt": 1000000 }
5
}
6
}
Copied!
...into this call to MongoDB:
1
db.my_collection.find({"collection": "people", "query": {"views": {"$gt": 10000000 }}})
Copied!
Here are some other examples of MongoDB queries you can write with LogicLoop.

Count

1
{
2
"collection": "my_collection",
3
"count": true
4
}
Copied!

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:
1
{
2
"collection": "things",
3
"aggregate": [{
4
"$unwind": "$tags"
5
}, {
6
"$group": {
7
"_id": "$tags",
8
"count": {
9
"$sum": 1
10
}
11
}
12
}, {
13
"$sort": [{
14
"name": "count",
15
"direction": -1
16
}, {
17
"name": "_id",
18
"direction": -1
19
}]
20
}]
21
}
Copied!

MongoDB Extended JSON Support

We support MongoDB Extended JSON along with our own extension - $humanTime:
1
{
2
"collection": "date_test",
3
"query": {
4
"lastModified": {
5
"$gt": {
6
"$humanTime": "3 years ago"
7
}
8
}
9
},
10
"limit": 100
11
}
Copied!
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.
1
{
2
"collection": "zipcodes",
3
"aggregate": [{
4
"$project": {
5
"_id": "$_id",
6
"city": "$city",
7
"loc": "$loc",
8
"pop": "$pop",
9
"state::filter": "$state"
10
}
11
}]
12
}
Copied!
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:
1
{
2
...
3
"allowDiskUse": true
4
}
Copied!
Copy link