Docs Menu

Copy and Bundle a Realm File - .NET SDK

On this page

  • Copy a Realm File
  • Include the Realm File in Your Project
  • Using the Copied Realm File

You might want to seed your mobile app with some initial data that will be available to users on the initial launch of the app. To do this, you:

  • Build a temporary realm app,
  • Make a copy of an existing realm (with only the data you want bundled), and then
  • Bundle the Realm file in your app's shared project.

In your production app (the one that will use this bundled realm when first loading), you add a few lines of code to extract the realm and save it in the app data. The following sections provide more information on these steps.

Synced Realms Are Not Supported

For now, bundling a synced realm is not supported. If you are using Sync, the local database will be synced when it is initialized.

  1. Create a new project with the same data models as your production app. Open an existing realm with the data you wish to bundle.
  2. Use the WriteCopy() method to make a copy of the realm to a new location and/or name. The following code demonstrates this:

    // open an existing realm
    var realm = Realm.GetInstance("myRealm.realm");
    // Create a RealmConfiguration for the *copy*
    var config = new RealmConfiguration("bundled.realm");
    // Make sure the file doesn't already exist
    // Copy the realm
    // Want to know where the copy is?
    var locationOfCopy = config.DatabasePath;

Now that you have a copy of the realm with the "seed" data in it, you need to bundle it with your production application. The process of bundling depends on whether you are building a mobile app or Unity app:

Cross-Platform Compatibility

Non-encrypted realm files are cross-platform compatible, which is why you can bundle the file in the shared project.

Now that you have a copy of the realm included with your app, you need to add code to use it. The code you add depends on the type of app:

Give Feedback
© 2021 MongoDB, Inc.


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