We support the following keys in MongoDB query builder to get answers from your database.

Key name Data type Purpose of the key
collection string To specify the collection to run the query on
filters object To perform filters on your data
aggregate array To add aggregate pipelines in your query
count boolean To perform count query
sort object To add sorting keys for the result
fields object/array To specify keys to display in the result

Sample Collection Query

{
	"collection": "users",
	"filters": {
		"organization": "notion"
	},
	"fields": {
    "_id": 0,
    "name": 1,
    "email": 1,
		"age": 1
  },
	"sort": {
		"age": 1
	}
}

We use MongoDB Extended JSON to help query MongoDB. Some common queries using MongoDB:

Filter by Object ID

{
	"collection": "users",
	"filters": {
		"_id": {
			"$oid": "<id>"
		}
	}
}

Filter by date

{
  "collection": "events",
	"filters": {
		"actionCompleteOn": {
			"$gt": {
				"$date": "2022-07-11T00:00:00.000Z" // ISO-8601 Date/Time format        
			}
		}
	}
}

Filter by date using the timestamp

{
  "collection": "events",
	"filters": {
		"actionCompleteOn": {
			"$gt": {
				"$date": {
					"$numberLong": "1640995200000" // timestamp in milliseconds
				}
			}
		}
	}
}

Filter by regex

{
  "collection": "users",
  "filters": {
    "email": {
      "$regularExpression": {
        "pattern": "(\\\\W|^)[\\\\w.+\\\\-]*@gmail\\\\.com(\\\\W|$)",
        "options": "i"
      }
    }
  }
}

Options in the regex can be

  1. i for case insensitive match
  2. m for multiline matching for starting with query
  3. x ignore all white space characters unless escaped
  4. s for allowing. character to match all characters including the newline character

Aggregation Queries

We use aggregation pipelines to perform the aggregate query on your database. Just make sure to use the EJSON as specified above to perform any $match operations on non-JSON data types.