Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-497

Can't get realm sync to work with anonymous authentication

      I'm attempting to get a list of items from a MongoDB Atlas instance via Realm into my Xamarin Forms application. I'm pretty sure I've followed the instructions correctly, however I can't seem to see any values come in.

      I'm using Realm and Realm.Fody version: 10.2.0

      I've uploaded my data with the following script

      mongoimport --uri mongodb+srv://[user]:[pass]@cluster0.[wxyz].mongodb.net/[company] --collection products --type json --file products --jsonArray
      

      > 1057 document(s) imported successfully. 0 document(s) failed to import.

      When I go to MongoDB Atlas, I see this
      [![enter image description here][1]][1]

      In my App.xaml.cs constructor, I create a realm app and log in with anonymous credentials

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      public const string MasterDataPartitionKey = "master_data";
      ctor()
      {
          var app = Realms.Sync.App.Create("my-app-id");
      	app.LogInAsync(Credentials.Anonymous()).ContinueWith(task => User = task.Result);
      }
      

      After this, in my first ViewModel constructor (it's Rx, but isn't doing anything fancy)

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      ctor()
      {
      	_listProductsCommand = ReactiveCommand.Create<Realm, IEnumerable<Product>>(ExecuteLoadProducts);
      
      	_listProductsCommand.ThrownExceptions.Subscribe(x => { /* checking for errors here */ }).DisposeWith(TrashBin);
      	Initialize
      		.ObserveOn(RxApp.MainThreadScheduler)
                      // note MasterDataPartitionKey is the value I've set on every single record's `_partitionKey` property.
      		.Select(_ => new SyncConfiguration(MasterDataPartitionKey, App.User))
      		.SelectMany(Realm.GetInstanceAsync)
      		.Do(_ => { }, ex => {  /* checking for errors here */ })
      		.ObserveOn(RxApp.MainThreadScheduler)
      		.InvokeCommand(this, x => x._listProductsCommand)
      		.DisposeWith(TrashBin);
      }
      

      And later, a simple query

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      private static IEnumerable<Product> ExecuteLoadProducts(Realm realm)
      {
      	var data = realm.All<ProductDto>();
      	var productDtos = data.ToList();
      	var products = productDtos.Select(x => x.Map());
      	return products;
      }
      

      Expected:
      productDtos (and products) should have a count of 1057

      Actual:
      productDtos (and products) have a count of 0

      I've looked in my Realm logs and I can see the connections and sync logs

      [![enter image description here][2]][2]
      [![enter image description here][3]][3]

      My anonymous authentication is turned on

      [![enter image description here][4]][4]

      and I've made it so that all of my Collections have read access (in fact developer mode is on)

      Here's an example of one of the records
      [![enter image description here][5]][5]

      Here's a snipped of the dto I'm trying to pull down
      [![enter image description here][6]][6]

      I feel as though I must be missing something simple. Can anyone see anything obvious that could be sending me sideways?

      [1]: https://i.stack.imgur.com/N07B5.png
      [2]: https://i.stack.imgur.com/asJGN.png
      [3]: https://i.stack.imgur.com/ryWRx.png
      [4]: https://i.stack.imgur.com/eDpq6.png
      [5]: https://i.stack.imgur.com/pU8vu.png
      [6]: https://i.stack.imgur.com/n3RQg.png

      Version of Realm and Tooling

      • Flavor:
        • [x] MongoDB Realm
        • [ ] Local Database only
      • Client SDK Version: ? Realm and Realm.Fody version: 10.2.0
      • Client OS & Version: ? iPhone 11 Pro Max / iOS 14.5

            Assignee:
            nikola.irinchev@mongodb.com Nikola Irinchev
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: