Certain information in this article may be missing or out of date. We are in the process of updating the content.

Connecting to MongoDB

To connect to a MongoDB account, you will follow the general instructions for connecting most databases.

FAQs + Tips and Tricks

How can I make sure my data is secure?

We have several items in place to keep your data safe.CHeck out our security article to see what steps you can take to keep control of your data.

Queries honor the aggregation pipeline

Your Mongo queries honors the aggregation pipeline. You can find more info about the pipeline here. For example, the $match and $sort pipeline operators can take advantage of an index when they occur at the beginning of the pipeline. Here are some examples of aggregation provided by Mongo.

Limiting the Data by Specifying a Date Range

If you want to only bring in a certain amount of data form your database (for example, the last 6 months) then you can do that with the following code:

"$dateFromString": {
"dateString": "{{date('-6months','YYYY-MM-DD')}}"

This will only work for v3.6 and above.

You can change this code {date('-6months','YYYY-MM-DD')} to dynamically select how far back the data should go. Learn more about the options for selecting the dates, read our article on using the date interpolator.

Here's another example of building a simple query that pulls the data from the last 7 days:

"$match": {
"$expr": {
"$gt": [
"$dateFromString": {
"dateString": "{{date('-7days','YYYY-MM-DD')}}"

You can read more about using $dateFromString in MongoDV's documentation.

Rules and How to Query

This article assumes you have some knowledge of MongoDB and JSON and are comfortable writing queries.

Key notes: Anything written in the query needs to be valid JSON. This includes key names, helper functions, aggregation and operators etc.


Any valid query will work, as long as it is valid JSON. Notice that an empty query is still valid JSON.


When you make a query, it needs to be valid JSON. In this example winner should be wrapped in double quotes. {"winner": "Fox"}


When using the find method, up to 10,000 records will be returned if the where clause is empty.


Everything written in the query on the find method (or any method) needs to be valid JSON, which includes wrapping every key in double quotes.


Even help functions like $gt need to be wrapped in double quotes to make them valid JSON. Numbers and booleans do not need to be wrapped since they are still valid JSON unwrapped.


The $or operator needs to be wrapped in double quotes as well.


Aggregation functions follow the same pattern, and need to be wrapped in double quotes.


Was this article helpful?