title: Disable Realm Sync only for non-premium users
body: <p>I'm creating an iOS application, where I intend to provide data sync across device feature, only to the premium users. I find <a href="https://docs.mongodb.com/realm/sync/" rel="noreferrer">Realm Sync</a> as a good solution to keep the local on-device database and cloud MongoDB Atlas in sync. However, I don't want to sync the data of the non-premium users to the cloud database.</p>
  <p>I'm enlisting a couple of ways that I can think of to prevent Realm Sync from triggering for non-premium users, but I'm not sure on what is the best way for this problem.</p>
  <ul>
  <li><p>Prevent syncing by leveraging <a href="https://docs.mongodb.com/realm/sync/permissions/" rel="noreferrer">Sync permissions</a> - I can store list of premium user ids and only give sync permissions to those users.</p>
  <pre><code> {
     &quot;%%user.id&quot;: [
        &quot;5f4863e4d49bd2191ff1e623&quot;,
        &quot;5f48640dd49bd2191ff1e624&quot;,
        &quot;5f486417d49bd2191ff1e625&quot;
     ]
   } 
  </code></pre>
  </li>
  <li><p><a href="https://docs.mongodb.com/realm/tutorial/ios-swift/" rel="noreferrer">Configure Realm objects</a> on client side i.e. only allow all Realm objects / models if the user is premium.</p>
  <pre><code> // Get a configuration to open the synced realm.
   var configuration = user.configuration(partitionValue: &quot;user=\(user.id)&quot;)
   // For non-premium user it would be [User.self]
   configuration.objectTypes = [User.self, Project.self] 
   Realm.asyncOpen(configuration: configuration) { [weak self](result) in /*...*/ }
  </code></pre>
  </li>
  </ul>
  <p>I'm looking for insights / recommended approach to this problem.</p>
  <p><strong>Edit</strong></p>
  <p>I've a few additional questions about handling two use cases differently - non-premium one by opening a local only <code>Realm()</code> and the premium one with <code>Realm.asyncOpen()</code>.</p>
  <ol>
  <li>How to handle a use case when an existing user switches to a premium subscription? Should calling <code>Realm.asyncOpen()</code> suffice or do I need to do any special handling?</li>
  <li>I plan to sync all my <code>User</code> (custom document in a collection) records for all users (premium + non-premium). My guess is I should open a normal Realm for all my conent and synced Realm with just <code>[User.self]</code> object in the configuration.</li>
  </ol>