> For the complete documentation index, see [llms.txt](https://docs.cosmocloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cosmocloud.io/advanced-guide/mongodb-query-language.md).

# MongoDB Query Language

Cosmocloud is natively integrated with MongoDB as the primary database and can run native MongoDB Queries.

Custom MongoDB queries can be written supported in these nodes -

* [Custom Query Records](/flow-builder/node-types/database-nodes/run-aggregation-pipeline.md)
  * Supports Aggregation Pipelines
* [Update Record](/flow-builder/node-types/database-nodes/update-by-id.md)
  * Support MongoDB Update Query
* [Update Multiple Records](/flow-builder/node-types/database-nodes/update-many.md)
  * Support MongoDB Update Query
* [Delete Multiple Records](/flow-builder/node-types/database-nodes/delete-many.md)
  * Supports MongoDB Delete Query

{% hint style="info" %}
To learn more about MongoDB Query Language, you can check the official [documentation of MongoDB](https://docs.mongodb.com/manual).
{% endhint %}

## BSON to EJSON

*MongoDB Extended JSON (EJSON)* is a string format for representing BSON documents. This specification defines the canonical format for representing each BSON type in the Extended JSON format.

**Cosmocloud supports MongoDB Queries converted in Extended JSON format**. You need to convert some of the rich BSON features (such as `ObjectID`) to EJSON way to represent the same.

For example, you might have a sample aggregation query like this -

```javascript
[
    {
        "$match": {
                "paymentId": ObjectId("123456789012345678901234")
        }
    }
]
```

As JSON does not support custom classes like `ObjectId` and similar, you need to convert the same into EJSON format as below -

<pre class="language-json"><code class="lang-json"><strong>[
</strong>    {
        "$match": {
                "paymentId": {
                        "$oid": "123456789012345678901234"
                }
        }
    }
]
</code></pre>

As you can see, each special item in MongoDB query can be converted to EJSON structure, so that the system can easily read it and pass the same to MongoDB.

### Conversion table

<table><thead><tr><th width="275">BSON Type</th><th>Canonical Extended JSON Format</th></tr></thead><tbody><tr><td>ObjectId</td><td><p>{"$oid": &#x3C;ObjectId bytes as 24-character, big-endian <em>hex string</em>>}<br><br><em>Example -</em> </p><pre class="language-json"><code class="lang-json">{
    "$oid": "123456789012345678901234"
}
</code></pre></td></tr><tr><td>Regular Expression</td><td><p>{"$regularExpression": {pattern: <em>string</em>, "options": &#x3C;BSON regular expression options as a <em>string</em>>}}<br><br><em>Example -</em> </p><pre class="language-json"><code class="lang-json">{
    "$regexExpression": {
        "pattern": "something",
        "options": "i"
    }
}
</code></pre></td></tr><tr><td>Datetime Object<br>(Canonical form)</td><td><p>{"$date": {"$numberLong": &#x3C;epoch in millisec, as a <em>string</em>>}}<br><br><em>Example -</em> </p><pre class="language-json"><code class="lang-json">{
    "$date": {
        "$numberLong": "1713767901000"
    }
}
</code></pre></td></tr><tr><td>Datetime Object<br>(Relaxed form)</td><td><p>{"$date": "ISO Datetime Format with maximum time precision of milliseconds, as a <em>string</em>"}<br><br><em>Example -</em></p><pre class="language-json"><code class="lang-json">{
    "$date": "2024-04-22T06:38:21.125Z"
}
</code></pre></td></tr><tr><td>Boolean</td><td>true or false</td></tr><tr><td>Null</td><td>null</td></tr></tbody></table>

For more references, you can check the [official specification document](https://github.com/mongodb/specifications/blob/master/source/extended-json.rst#conversion-table).
