I'd like to open another realm in changeEvent call to copy information to it. Like there is follower, and if I add new post it should be copied to followers table also. Opening Sync realm does not help much, looks like it has no data in it
You should try Realm.openAsync()
, which will ensure that the Realm is synced before it is returned to the callback. However, this does not ensure that the Realm will be synced before the first time the handler is fired.
Here's a quick example:
const Realm = require('realm');
const server_url = 'realm://localhost:9080';
const REALM_ADMIN_TOKEN = "insert token here";
const adminUser = Realm.Sync.User.adminUser(REALM_ADMIN_TOKEN);
console.log("Opening admin realm");
var adminRealm = null;
Realm.openAsync({sync: {user: adminUser, url: server_url + '/some-realm'}, readOnly: true}, (realm) => {
adminRealm = realm;
console.log("Admin Realm loaded");
});
// your handler code here.