Getting started querying sync data from Realm

Viewed 248

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

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

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)

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

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 enter image description here

My anonymous authentication is turned on

enter image description here

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

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

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

0 Answers
Related