Getting Started example doesn't work


#1

Hi!

I have created account in Cloud realm and tried to go ahead by Getting Started from Realm Studio.

I have created user with password and copied source code to my js file, but it didn’t work in my case.
I saw this error


I happens on Realm.open call.

Here is source code of example

const faker = require('faker')
const Realm = require('realm')
const fs = require('fs')

const totalTickers = 100
const USERNAME = "some-user" // I changed user name
const PASSWORD = "a-very-secure-password" // and password too
const SERVER = "{my instance was here}.us1a.cloud.realm.io"

const TickerSchema = {
  name: 'Ticker',
  primaryKey: 'tickerSymbol',
  properties: {
    tickerSymbol: { type: 'string', optional: false },
    price: { type: 'int', optional: false },
    companyName: { type: 'string', optional: false },
  }
}

const token = "I removed toke from here";

// Unlock Professional Edition APIs
Realm.Sync.setFeatureToken(token);

function generateRandomTickerSymbol(len) {
  charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  let randomString = '';
  for (let i = 0; i < len; i++) {
    let randomPoz = Math.floor(Math.random() * charSet.length);
    randomString += charSet.substring(randomPoz, randomPoz + 1);
  }
  return randomString;
}

function getStarted() {
    Realm.Sync.User.login(`https://${SERVER}`, USERNAME, PASSWORD)
    .then(user => {
        // Realm doesn't work
        Realm.open({
            sync: {
                url: `realms://${SERVER}/~/tickers`,
                user: user
            },
            schema: [TickerSchema],
        })
        .then(realm => {
            let tickerResults = realm.objects('Ticker')
            // Add some data to the tickers Realms
            if (tickerResults.length < totalTickers) {
                realm.write(() => {
                    for (let index = 0; index < totalTickers; index++) {
                        realm.create('Ticker', {
                            tickerSymbol: generateRandomTickerSymbol(3),
                            price: index,
                            companyName: faker.company.companyName()
                        }, true)
                    }
                })
            }

            tickerResults.addListener((objects, changes) => {
                changes.modifications.forEach((index) => {
                    const ticker = objects[index];
                    console.log(`Ticker ${ticker.companyName} - ${ticker.tickerSymbol} - ${ticker.price}`)
                });
            })
        })
    })
}

getStarted()

Has anyone seen that before?


#2

What is the version of the js SDK that you’re using? Version 2.3.0 is not yet compatible with the version of ROS deployed automatically on cloud instances. We’re in the process of testing a new ROS version and we’ll roll it out as soon as it passes QA. In the meantime, you can either downgrade to 2.2.15 or let us know your instance name and we can deploy a compatible (albeit prerelease) version of ROS on it.


#3

Hi! I use "realm": "^2.3.0",. I will wait for a new version. Could you give me version of this SDK?


#4

Any changes in my case?


#5

Sorry for the delay - I must have missed your update. Yes, a new version has been deployed across all instances and you should not be seeing this issue with realm-js 2.3.0 or later.