Docs Menu

Connect Over the Wire Protocol

On this page

  • Overview
  • Prerequisites
  • Compatible Clients
  • Usage
  • Connect to Realm with a Connection String
  • Perform CRUD Operations
  • Call a Function
  • Call a Service Function
  • Get the Logged In User's Data

MongoDB Realm natively implements a subset of the MongoDB wire protocol, which allows you to connect to a Realm app through one of its linked MongoDB clusters using standard MongoDB drivers and tools. Clients use a specialized MongoDB Realm connection string to connect and send requests. MongoDB Realm supports most client features over the wire protocol, including role-based data access rules, functions, and service actions.

This is a good choice for languages that do not currently have a Realm SDK. The examples here are for Python, C++11, and the Mongo Shell. Any MongoDB driver that supports the appName connection string parameter can use the wire protocol to connect to MongoDB Realm.

You must enable wire protocol connections for one or more linked clusters in your application before you can connect over the wire protocol.

Note

You can use the following tools and drivers to communicate with MongoDB Realm using a connection string:

  • Version 4.0+ of the mongo shell.
  • Any MongoDB driver that supports the appName connection string parameter. All official MongoDB drivers support this parameter in their current releases.
Note

Connections to MongoDB Realm over the wire protocol have access to the full functionality of the MongoDB Service. However, MongoDB Realm does not support all operations and features available in standard tools and clients. For details, see MongoDB Service Limitations.

To connect to MongoDB Realm over the wire protocol, pass a URL-encoded MongoDB Realm connection string when you create a client, just as you would with a regular connection string.

While connected to MongoDB Realm over the wire protocol you can use standard MongoDB CRUD operations. MongoDB Realm applies role-based data access rules to all queries in the context of the authenticated user specified in the connection string credentials.

You can call functions using the callFunction database command.

Command
Description
Prototype
callFunction
Calls the specified function and returns any result.
{
callFunction: <function name>,
arguments: [<arg1>, <arg2>, ...]
}

You can call service actions using the callServiceFunction database command.

Command
Description
Prototype
callServiceFunction
Calls the specified service action and returns any result.
{
callServiceFunction: <function name>,
service: <service name>,
arguments: [<arg1>, <arg2>, ...]
}

You can get the user object for the authenticated user using the userProfile database command.

Command
Description
Prototype
userProfile
Returns the user object for the authenticated user.
{
userProfile: 1
}
Give Feedback
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.