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 |
{
"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:
{
"collection": "users",
"filters": {
"_id": {
"$oid": "<id>"
}
}
}
{
"collection": "events",
"filters": {
"actionCompleteOn": {
"$gt": {
"$date": "2022-07-11T00:00:00.000Z" // ISO-8601 Date/Time format
}
}
}
}
{
"collection": "events",
"filters": {
"actionCompleteOn": {
"$gt": {
"$date": {
"$numberLong": "1640995200000" // timestamp in milliseconds
}
}
}
}
}
{
"collection": "users",
"filters": {
"email": {
"$regularExpression": {
"pattern": "(\\\\W|^)[\\\\w.+\\\\-]*@gmail\\\\.com(\\\\W|$)",
"options": "i"
}
}
}
}
Options in the regex can be
i
for case insensitive matchm
for multiline matching for starting with queryx
ignore all white space characters unless escapeds
for allowing.
character to match all characters including the newline characterWe 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.