Not able to sincronize nor write information to Realm

Hi, i’m currently having an issue, i’m trying to sync to realm using javascript and is not being possible, i see that the schema is being created in ROS but it’s empty.

am i mising something? or doing something wrong?

thanks a lot in advance.

this is the code…

const Weapons = {
name: ‘Weapons’,
properties: {
weaponName: ‘string’,
owner: ‘string’

const Superheroes = {
name: ‘Superheroes’,
properties: {
name: ‘string’,
superPower: ‘string’,
weapon: ‘string’

const authUrl = https://${constants.serverUrl};
let credentials = Realm.Sync.Credentials.usernamePassword(constants.username, constants.password);

Realm.Sync.User.login(authUrl, credentials).then(user => {
console.log("Server URL: " + authUrl);

//Setting the config against the Realm obj
let config = user.createConfiguration({
    sync: {
        user: user,
        url: `realms://${constants.serverUrl}/node-js-test`,
        error: (error) => {
            console.log(, error.message);
        //schema: [Weapons, Superheroes]
console.log("Realm URL: " + config.sync.url);
console.log("User: " + config.sync.user);

//Opening the specified Realm => {
    console.log("Realm opened...");
    //Writing data into the Schemas
    realm.write(() => {
        console.log("Starting to write...");

        //'Weapons' Schema
        realm.create('Weapons', {
            weaponName: 'Thor Hammer',
            owner: 'Thor'
        //'Superheroes' schema
        realm.create('Superheroes', {
            name: 'Thor',
            superPower: 'Lightning',
            weapon: 'Hammer'


}).catch(e => console.log(e));

}).catch(e => console.log(e));

I think you are closing the Realm (and the sync session) too early, and the objects haven’t time to get uploaded. Let me suggest that you call Realm.Sync.Session.uploadAllLocalChanges() and wait for it to complete before closing your Realm.

Hi Kneth thanks for the response! unfortunately the method that you suggested does not do the trick

const Realm = require('realm');

const Weapons = {
    name: 'Weapons',
    properties: {
        weaponName: 'string',
        owner: 'string'

const Superheroes = {
    name: 'Superheroes',
    properties: {
        name: 'string',
        superPower: 'string',
        weapon: 'string'

//setting the credentials
var cred = Realm.Sync.Credentials.usernamePassword("admin", "123");
console.log("credentials set...");

//setting the login
Realm.Sync.User.login("", cred).then(currentUser => {  

    console.log("logging user...");
    let config = currentUser.createConfiguration();
    config.schema = [Weapons];
    config.sync.user = currentUser;
    config.sync.url = "realms://";
    config.sync.fullSynchronization = true;
    config.sync.validate_ssl = false;
    console.log("Schema: " + + "\n" +
        "User: " + + "\n" +
        "Url: " + config.sync.url + "\n" + 
        "FullSync: " + config.sync.fullSynchronization + "\n" + 
        "Validate SSL: " + config.sync.validate_ssl + "\n" + "config done...\n");

    //open Realm with previously config object => {
        console.log("realm opened with configs...")
        let weapons = realm.objects('Weapons');

        realm.write(() => {
            var weapon = realm.create('Weapons',{
                owner: 'Cap',
                weaponName: 'Shield'
            }, true)


        }).catch(error => console.log(error));
    }).catch(error => {

}).catch(error => {

here there is again the snippet with the added piece of code… this is driving me crazy since i cannot find the solution…

here is a screenshot from the console, maybe this helps…

it seems that it never got passed the returns undefined as config.schema is an array. Moreover, Realm.Sync.User doesn’t have a property called name.

Please enable the sync logger (Realm.Sync.setLogger('all')) to get a better understanding of why hangs.

I’m new to Realm…could you please tell where in the code and how i insert that statement? thanks a lot in advance!

You can do something like:

const Realm = require('realm'); 
// Schemas 
const Weapons = { name: 'Weapons', properties: { weaponName: 'string', owner: 'string' } };

it’s giving me this…

Sorry, I meant Realm.Sync.setLogLevel('all').

now we got the logs…here’s what i got…

You have realm.commitTransaction(); outside a transaction, and it will throw an exception.

There were a few issues with your script - e.g. realm.commitTransaction outside of a write transaction and Realm.Sync.Session.uploadAllLocalChanges is not a static method but rather an instance method on the realm.syncSession object. I rewrote your script using async-await as it made the code flow more obvious and it seems to work for me:

Note that we’re aware of an incompatibility issue when running node10 on Windows and we’re working to resolve it. In the meantime, one workaround is to downgrade to node 8 or use a different operating system.