Having issues with sync realm and 2.20.0 API


#1

I’m having trouble working with a synchronized realm on ROS v3.13.1 with the 2.20.0 javascript API.

Whenever I try to do something simple like open a new Realm with a schema, I can login and create the new Realm, but the realm shows as having no classes defined in Realm Studio. I have tried writing creating an object or two as well to see if maybe that would work, but the outcome is the same.

Oddly, I can still create a new realm with models/objects when using the 2.9.0 API, even though the compatibility page appears to suggest otherwise. Is anyone else having a similar experience, and maybe were able to resolve it? I think it might be an issue with some other aspect of my environment but I am not sure. I have tried to get this to work with both node v8.12.0 and v10.13.0. Thanks for your time :slight_smile:

Code sample:

const Realm = require('realm');
const Models = require('./models/index.js');
const RealmConfig = require('./config/realmConfig.js');

function main() {
    const config = {
        sync: {
            user: null,
            url: 'realm://' + RealmConfig.serverUrl + RealmConfig.remoteRealmPath,
        },
        path: './appdata2.realm',
        schema: Models.schema,
    };

    const credentials = Realm.Sync.Credentials.usernamePassword(RealmConfig.username, RealmConfig.password);

    Realm.Sync.User.login('http://' + RealmConfig.serverUrl, credentials).then((user, error) => {
        if(!error){
            console.log(user);
            config.sync.user = user;

            Realm.open(config).then((realm, error) =>{
                if(!error){
                    console.log("Realm opened");
                    realm.close()
                    console.log("Realm closed");
                } else {
                    console.log(error);
                }                    
            });
        } else {
            console.log(error);
        }            
    });
};

main();```

#2

@kalex You should not be specifying a path parameter in your config - that is for non-synced Realms - please remove that.

Also are you logging in with an admin user? If not, please try that.

Additionally, it doesn’t appear that you are doing anything with the realm - you simply open it and then close it. Try open the realm and setTimeout before closing.

if it still doesn’t work please set Realm.Sync.setLogLevel('trace'); and share the output on node client and server.


#3

Thanks for the response ianward,

I’ve updated my code with a setTimeout on the realm.close() for 30 seconds. It is worth noting however that the script gave me output and terminated almost immediately (within a second or two).

The code I used was as follows:

const Realm = require('realm');
const Models = require('./models/index.js');
const RealmConfig = require('./config/realmConfig.js');

function main() {
    const config = {
        sync: {
            user: null,
            url: 'realm://' + RealmConfig.serverUrl + RealmConfig.remoteRealmPath,
        },
        schema: Models.schema,
    };

    const credentials = Realm.Sync.Credentials.usernamePassword(RealmConfig.username, RealmConfig.password);

    Realm.Sync.setLogLevel('trace');

    Realm.Sync.User.login('http://' + RealmConfig.serverUrl, credentials).then((user, error) => {
        if(!error){
            config.sync.user = user;

            Realm.open(config).then((realm, error) =>{
                if(!error){
                    console.log("Realm opened");
                    setTimeout(() => {realm.close(); 
                        console.log("Realm closed");}, 30000);
                } else {
                    console.log(error);
                }                    
            });
        } else {
            console.log(error);
        }            
    });
};

main();

I’m not sure how much of the trace output I can share - I’d like to double-check with my department’s lead developer first to be safe.

It did, however, return output that suggested that it was disconnecting pretty much immediately, then trying to pen a new connection, which I thought was weird. None of the code in the callback in setTimeout ever executed, and the 30 second wait did not occur.

Connection[1]: Session[1]: Deactivation completed
Connection[1]: Allowing reconnection in 649 milliseconds
Connection[1]: Disconnected
Connection[1]: Destroying connection object
Realm opened
Connection[2]: WebSocket::Websocket()