On this page
This page contains information to quickly get Realm Database integrated into your app. Before you begin, ensure you have:
This page contains only the essential information that you need to set up a MongoDB Realm application. 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 MongoDB Realm, add the following line to import the SDK.
To use MongoDB Realm features such as authentication and sync, you must access your Realm app using your Realm app ID. You can find your Realm app ID in the Realm UI.
If you have enabled Sync but turned off Development Mode, you can copy and paste the object model definitions that Realm generated for you from the SDKs tab in the Realm UI. You must re-enable Development Mode if you want to make changes to the object model definition from client side code.
When you have enabled anonymous authentication in the Realm UI, users can immediately log into your app without providing any identifying information:
Realm provides many additional ways to authenticate, register, and link users.
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:
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: