Cosmocloud Build Documentation
DocumentationTutorials
  • Welcome to Cosmocloud
  • Getting Started
    • 1. Organisations
    • 2. Projects
    • 3. Connect your Database
    • 4. Create Database Models
    • 5. Create APIs
    • 6. Testing Free Tier APIs
  • Free Tier
    • Connecting with MongoDB Data APIs
  • Templates
    • CRUD APIs
    • Entity Search APIs
    • Fetch / Upload Media APIs
  • Examples - How To?
    • Making an external API call
    • Reusable Flows - SubFlows
    • Creating Custom Error Responses
    • Flow Builder - Building Conditional Logics
    • Flow Builder - Utilising Loops
    • Creating Dynamic Queries
    • Accessing Auth Tokens in APIs
    • How to upload/download media in Object Storage
  • Resources
    • APIs
      • Checking Logs
    • SubFlows
    • Models
      • Building Models
    • Environments
      • Environment Tier Types
    • Secrets
      • Custom Secrets
    • Databases
    • Releases
    • Vector Search
      • Create a Vector Search Index
      • Edit a Vector Search Index
      • Delete a Vector Search Index
    • Document Search
      • Full Text Search
        • Concepts
          • Indexing in full-text search
          • Data processing using Analyzers
        • Create a Search Index
        • Creating a Custom Analyzer
        • Full Text Search FAQ
      • Vector Search
    • Object Storage
  • Flow Builder
    • Node Types
      • Trigger Nodes
        • HTTP Response
      • Conditional Nodes
        • If Else
        • If Else V2
        • Switch Case
      • Crypto Nodes
        • PBKDF2 Hmac Hash
      • Debug Node
      • Database Nodes
        • Delete One
        • Delete Many
        • Fetch By ID
        • Find One
        • Find Many
        • Insert One
        • Insert Many
        • List Records
        • Run Aggregation Pipeline
        • Update One
        • Update by ID
        • Update Many
      • External Nodes
        • Fire Events (SQS)
        • API Call
        • Delete storage objects
        • Execute SubFlow
        • Get Presigned URL
        • Post Presigned URL
        • Send EMAIL (SES)
        • Send SMS (SNS)
      • Loop Nodes
        • For loop
        • While loop
      • Variable Nodes
        • Arrays
          • Append array
          • Contains
          • Check array empty
          • Extend array
          • Get Array Item
          • Length of array
          • Reverse array
          • Sort array
        • Date and Time
          • Set current datetime
        • Strings
          • Append String
          • Concat Strings
          • Convert to String
          • Length of String
          • Slice String
          • Split String
          • String Operations
          • To Lower
          • To Upper
          • Trim String
        • Mathematical
          • Add Variable
          • Complex Math Expr
          • Decrement Variable
          • Divide Variable
          • Increment Variable
          • Multiply Variable
          • Subtract Variable
        • JSON
          • Build JSON Object
          • Merge JSON Objects
          • Object to String
          • Update JSON Object
        • Special
          • Build Map
          • Set Variable
          • Exists Check
    • Node name
    • CQL - Cosmocloud Query Language
      • Building Expressions
        • $abs
        • $add
        • $addDate
        • $arrayElemAt
        • $avg
        • $buildDateTime
        • $buildMap
        • $ceil
        • $cond
        • $divide
        • $floor
        • $getDay
        • $getHour
        • $getMinute
        • $getMonth
        • $getSecond
        • $getYear
        • $ifNull
        • $max
        • $min
        • $mod
        • $multiply
        • $pow
        • $subtract
        • $sqrt
      • Building Conditions
        • Compound Operators
          • $and
          • $or
        • Conditional Operators
          • $eq
          • $gt
          • $gte
          • $lt
          • $lte
          • $neq
      • Magical Autocomplete
  • Advanced Guide
    • Configuring Authentication
      • SSO Providers
        • AWS Cognito
      • Authentication Concepts
    • MongoDB Query Language
      • Limitations
    • Performance Considerations
      • Instant Deployments
  • User Management
  • Billing and Payments
    • Billing Portal
  • Help & Support
  • References
    • Change log
    • Available Cloud & Regions
Powered by GitBook
On this page
  • BSON to EJSON
  • Conversion table
  1. Advanced Guide

MongoDB Query Language

PreviousAuthentication ConceptsNextLimitations

Last updated 1 year ago

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 -

    • Supports Aggregation Pipelines

    • Support MongoDB Update Query

    • Support MongoDB Update Query

    • Supports MongoDB Delete Query

To learn more about MongoDB Query Language, you can check the official .

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 -

[
    {
        "$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 -

[
    {
        "$match": {
                "paymentId": {
                        "$oid": "123456789012345678901234"
                }
        }
    }
]

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

BSON Type
Canonical Extended JSON Format

ObjectId

{"$oid": <ObjectId bytes as 24-character, big-endian hex string>} Example -

Regular Expression

{"$regularExpression": {pattern: string, "options": <BSON regular expression options as a string>}} Example -

Datetime Object (Canonical form)

{"$date": {"$numberLong": <epoch in millisec, as a string>}} Example -

Datetime Object (Relaxed form)

{"$date": "ISO Datetime Format with maximum time precision of milliseconds, as a string"} Example -

Boolean

true or false

Null

null

For more references, you can check the .

{
    "$oid": "123456789012345678901234"
}
{
    "$regexExpression": {
        "pattern": "something",
        "options": "i"
    }
}
{
    "$date": {
        "$numberLong": "1713767901000"
    }
}
{
    "$date": "2024-04-22T06:38:21.125Z"
}
Custom Query Records
Update Record
Update Multiple Records
Delete Multiple Records
documentation of MongoDB
official specification document