Docs Menu

Docs HomeRealm

Quick Start with Sync - React Native SDK

On this page

  • Overview
  • Import Realm
  • Initialize the App
  • Define Your Object Model
  • Authenticate a User
  • Open a Realm
  • Create, Read, Update, and Delete Objects
  • Watch for Changes
  • Log Out

This page contains information to quickly get Realm Database integrated into your app. Before you begin, ensure you have:

  • Created an App

  • Enabled Device Sync

  • Installed the Node SDK to use with your Realm Native app.


Check Out the Tutorial

This page contains only the essential information that you need to set up an Atlas App Services backend. If you prefer to follow a guided tutorial that shows you step-by-step how to set up a working app, check out the React Native Tutorial where you'll build a mobile app that connects to the Task Tracker backend.

At the top of your source files where you want to use Realm, add the following line to import the SDK.

To use App Services features such as authentication and sync, you must access your App using your App ID. You can find your App ID in the App Services UI.

If have not enabled Device Sync or you enabled Sync with Development Mode in the App Services UI, you can define your object model directly in code.


Get Schema from UI if Development Mode Disabled

If you have enabled Sync but turned off Development Mode, you can copy and paste the object model definitions that App Services generated for you from the SDKs tab in the App Services UI. You must re-enable Development Mode if you want to make changes to the object model definition from client side code.

Learn more in the documentation for creating a schema.

When you have enabled anonymous authentication in the App Services UI, users can immediately log into your app without providing any identifying information:

Realm provides many additional ways to authenticate, register, and link users.


Once you have enabled Device Sync and authenticated a user, you can open a synced realm:

Once you have opened a realm, you can modify it and its objects in a write transaction block.

To create a new Task run the method "realm.create()" inside the "realm.write()" callback. Pass the string "Task" as the first parameter to "realm.create()". Pass a task object as the second parameter.

You can retrieve a live collection of all tasks in the realm:

You can also filter that collection using a filter:

To modify a task, update its properties in a write transaction block:

Finally, you can delete a task:

You can watch a realm, collection, or object for changes by registering event handlers with the Realm.addListener() Object.addListener() Collection.addListener() methods.


Serverless Limitations

You cannot watch for changes if the data source is an Atlas serverless instance. MongoDB serverless currently does not support change streams, which are used on watched collections to listen for changes.

To stop watching for changes, run the "realm.removeAllListeners()" method. Alternatively, to remove a specific listener, call "removeListener()" on the object that is being watched and pass in the listener function:

Once logged in, you can log out:

←  Quick Start - React Native SDKQuick Start with Expo - React Native SDK →
Give Feedback
© 2022 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.