Realm 10.1.0 not sync from server to client

Hi, I have wrote a simple code like old Realm Legacy.
I write a .Net Web App that connect to Sync MongoDbRealm. Collection appear on server, and when I create a new object from client, I view it on server.
But if I update or delete any document from server nothing appened on client
Permission is true/true for read & write

It’s a bug of 10.1.0?

What do you mean when you say nothing is happening on the client? Do you have some code you can share that demonstrates what you’re trying to do?

Hi! this is my code (in Legacy Realm works fine)

With MongoDbRealm, when I run NewCliente(…), a new Record is added in MongoCollection and it’s visible from view Index.
If I add record on MondoDB collection, Index() not show new record

namespace StudioProTest.Models
{
public class Cliente : RealmObject
{
[PrimaryKey]
[MapTo("_id")]
public string ID { get; set; } = Guid.NewGuid().ToString();

    [MapTo("_partition")]
    public string _partition { get; set; }

    [MapTo("nome")]
    public string Nome { get; set; }

    [MapTo("cognome")]
    public string Cognome { get; set; }

    [MapTo("isDone")]
    public bool IsDeleted { get; set; }

    [MapTo("timestamp")]
    public DateTimeOffset Timestamp { get; set; } = DateTime.Now;
}

}

Controller.cs

async public static Task GetRealm()
{

App app = App.Create(new AppConfiguration(Settings.AppId)
{
    MetadataPersistenceMode = MetadataPersistenceMode.NotEncrypted,
    LocalAppName = "TestNewRealm",
    LocalAppVersion = "1.0.0"
});

User user =  await app.LogInAsync(Credentials.Anonymous());

var config = new SyncConfiguration("test", user);
Realm realm = await Realm.GetInstanceAsync(config);

return realm;

}

public async Task NewCliente(string nome, string cognome)
{

var vRealmDb = await GetRealm();

Transaction trans =  vRealmDb.BeginWrite();

Cliente cliente = new Cliente
{
    Nome = nome,
    Cognome = cognome
};

vRealmDb.Add(cliente);                

trans.Commit();

return Redirect(nameOf(Index));

}

public async Task Index()
{
var vRealmDb = await GetRealm();

var list = vRealmDb.All<Cliente>();

return View(list);

}

Index.cstml:

@model IEnumerable<StudioProTest.Models.Cliente>

@foreach (Cliente cliente in Model) { }
@cliente.Nome @cliente.Cognome

Is there anything in the server logs that may look like an error?

No, this is log console:
Connection[1]: Session[1]: client_reset_config = false, Realm exists = true, async open = false, client reset = false
Connection[1]: Connected to endpoint ‘34.241.208.56:443’ (from ‘192.168.1.167:63069’)

When I update or delete a document in the collection Cliente on server, client not receive any change!

I observe that client update his data after that it changes any record or after a restart of web application.

Can you try calling realm.Refresh() before querying the Realm?

It’s works!!!
But Legacy Realm not required to call Refresh.
It’s also necessary for Xamarin App? The method is light for CPU/Processor?

When working with Realm instances on background threads (such as in console app or a web server), you’ll need to manually call Refresh to force the Realm to update itself. Opening a Realm instance for every request should be fine and it should automatically get refreshed, but you’re hitting a combination of issues:

  1. You’re not disposing of Realm files. This is generally a bad idea and means that the native instances will outlive your requests. This means that you can randomly get a reference to a cached native instance if a request happens to execute on the same thread as a previous one.
  2. GetInstance would have refreshed the Realm, but GetInstanceAsync has a bug and doesn’t refresh the Realm prior to resolving the task.

The combination of these means that you may end up with a stale Realm that needs to be manually refreshed. While we will fix the bug described in 2., I would strongly recommend that you dispose your Realm instances when you’re no longer using them. This will free native resources predictably and, more importantly, will prevent explosive file size growth.

Regarding Xamarin - this should not happen there because Xamarin apps have a main thread which allows Realm to automatically refresh itself in the background. If you open Realm instances on background threads in Xamarin apps, the recommendation is, again, to dispose of them as soon as you’re done using them.

1 Like

Ok perfect!

Thanks
Luigi

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.