CRUD & Aggregation APIs
On this page
Overview
This page lists MongoDB data source support for MongoDB commands, operators, options, and aggregation stages.
For information on how to read and write data in MongoDB from a function, see Query MongoDB Atlas.
For more information on supported features and limitations, see Service Limitations.
Support for an operation may depend on whether you're running the operation as an application user or as a system user.
- A user function runs in the context of a specific application user and enforces data access permissions and schema validation, which makes some operations untenable.
- A system function runs as a generic system user and is not subject to rules or schema validation. Some operations are only available in system functions.
CRUD Operations
Query Operators
MongoDB Realm supports most query operators for queries that run in a user function. However, some evaluation operators and all geospatial and bitwise operators are only available in system functions.
Comparison Operator Availability
Logical Operator Availability
Array Operator Availability
Operation | User Function | System Function |
---|---|---|
Yes | Yes | |
Yes | Yes | |
Yes | Yes |
Element Operator Availability
Evaluation Operator Availability
Geospatial Operator Availability
Operation | User Function | System Function |
---|---|---|
No | Yes | |
No | Yes | |
No | Yes | |
No | Yes |
Bitwise Operator Availability
Operation | User Function | System Function |
---|---|---|
No | Yes | |
No | Yes | |
No | Yes | |
No | Yes |
Update Operators
MongoDB Realm supports most update operators for queries that run in a user function. However, some array update operators are only available in system functions.
Field Update Operator Availability
Operation | User Function | System Function |
---|---|---|
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes |
Array Update Operator Availability
Operation | User Function | System Function |
---|---|---|
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes | |
Yes | Yes |
Array Update Operator Modifiers Availability
Bitwise Update Operator Availability
Operator | User Function | System Function |
---|---|---|
Yes | Yes |
Bulk Write Operations
MongoDB Realm supports bulk write operations using the same API as the MongoDB Node.js driver.
Realm also provides the collection.bulkWrite()
method for performing bulk write operations.
Ordered Bulk Write Operation Availability
You define ordered bulk operations by calling collection.initializeOrderedBulkOp() and manipulating the OrderedBulkOperation object that it returns.
Realm supports the following OrderedBulkOperation
methods:
Unordered Bulk Write Operation Availability
You define unordered bulk operations by calling collection.initializeUnorderedBulkOp() and manipulating the OrderedBulkOperation object that it returns.
Realm supports the following UnorderedBulkOperation
methods:
Query Options
MongoDB Realm does not support configuring the following options for any CRUD operation in user functions. All query options are available in system functions.
Query Option Availability
Option | User Context | System Context |
---|---|---|
No | Yes | |
No | Yes | |
No | Yes |
Aggregation
Aggregation Methods
MongoDB Realm supports aggregation on the both the database and collection level using the following commands:
Aggregation Pipeline Stage Availability
MongoDB Realm does not support the following aggregation pipeline stages when you run an aggregation
pipeline in the context of an
application user. All aggregation pipeline stages are
available to the system user except for $indexStats
.
Stage | User Context | System Context |
---|---|---|
No | Yes | |
No | Yes | |
No | Yes | |
No | Yes | |
No | Yes | |
No | No | |
Yes | Yes | |
No | Yes | |
No | Yes | |
Important Realm performs | Yes | Yes |
Yes | Yes |
By default, $merge
and $out
route the entire aggregation operation to
the cluster's primary node. If you want to force these stages to respect your
configured cluster read preference, set the enforceReadPref
option to
true
.
Aggregation Pipeline Operator Availability
MongoDB Realm supports all aggregation pipeline operators when you run an aggregation pipeline in the system user context. Realm supports all pipeline operators in an application user context with the following exceptions:
Operator | User Context | System Context |
---|---|---|
No | Yes |
Database Commands
MongoDB Realm does not support any database commands in the Client SDKs or Functions. You can, however, call a limited subset of database commands when connected to a MongoDB cluster over the MongoDB Realm wire protocol.
The following database commands are partially supported over the wire protocol. Unsupported options for each command are listed below.
Realm apps cannot run commands on the admin
database.
Database Command Availability
Command | Unsupported Options | Realm-Specific Options |
---|---|---|
| ||
|
| |
| ||
| ||
| ||
|