Could not open realm in partial mode

cloud

#1

Hey there.

I try to do something basic and very simple - open new realm database with “partial” mode.
I used code from “Get Started” example:

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

const totalTickers = 100;
const USERNAME = "test-admin";
const PASSWORD = "123456";
const SERVER = "some.link.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 = "some token";

// 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 => {
        //    let rdb = new Realm({sync: {user, url: `realms://${SERVER}/global6/tickers`,  fullSynchronization: false}});
            Realm.open({
                sync: {
                    url: `realms://${SERVER}/global9/tickers`,
                    user: user,
                    fullSynchronization: false
                },
                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)
                            }
                        })
                    }
                })
        })
}

getStarted()

I just added: fullSynchronization: false in the sync section.
And on run - I got error:

node client.js
Realm.Sync.setFeatureToken() is deprecated and you can remove any calls to it.
logged in as 27da39ae0d716adfdd9849246c7c2db8 isAdmin true
Error: Unable to open a realm at path 'C:\Users\yatree\WebstormProjects\rcload2\realm-object-server\da472290-da1d-4c23-996f-7274a63a7578\realms%3A
%2F%2Fgorgeous-rubber-shirt.us1.cloud.realm.io%2Fglobal88%2Ftickers%2F__partial%2F27da39ae0d716adfdd9849246c7c2db8%2F070bb1e094eb1658dad14ecf0403
5b18acc25928.management': make_dir() failed: No such file or directory.
    at Realm.Sync.User.login.then.user (C:\Users\yatre\WebstormProjects\rcload2\client.js:108:17)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

I run the script on Windows 10
NodeJS: v8.4.0
realm-js: 2.14.0 (got it from changelog file)

If I will change fullSync option to true - the script will work, on Realm Cloud realm will be created.
Did I miss something?


#2

Looks like the problem is that the generated path is too long for Windows. Can you try to run the script from C:\t or a similar folder with a short path?


#3

No. This does not help, but I solved it in another way :slight_smile: Switched to Linux.

I don’t want to create another’s topics, so will ask here several other questions.

This code is from realm docs:

// Example of restricting the object to the user creating it.
let user = Realm.Sync.User.current;

// Permissions must be modified inside a write transaction
realm.write(() => {
    // Create role unique to user
    let role = realm.create('__Role', { name: user.identity });
    role.members.push(user);
​
    // Create a new permission object for the role
    // and add it to the objects permissions
    let permission = realm.create('__Permission', { role: role });
    ['canRead', 'canUpdate', 'canDelete', 'canSetPermissions', 'canQuery', 'canCreate', 'canModifySchema'].forEach((p) => permission[p] = true);
​
    let objectPermissions = realm.objects('__Class').filtered(`class_name = 'Person'`)[0];
    objectPermissions.permissions.push(permission);
};

First of all - these objects: __Permission, __Class, _Rose, __Users were not in realm schema - I had added them, because of errors like this:

 Unhandled promise rejection (rejection id: 1): Error: Object type '__Class' not found in schema.

With Class object I have another problem:

(node:28153) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: The following changes cannot be made in additive-only schema mode:
- Primary Key for class '__Class' has changed from 'name' to 'class_name'.

I just used example script and code from the documentation. What is wrong?

And last problem:

Connection[1]: Connection closed due to error
Connection[1]: Connected to endpoint '52.25.46.81:443' (from '10.0.0.200:46696')
ERROR: Connection[1]: Websocket: Expected HTTP response 101 Switching Protocols, but received:
HTTP/1.1 502 Bad Gateway
Connection: keep-alive
Content-Length: 173
Content-Type: text/html
Date: Thu, 26 Jul 2018 19:27:29 GMT
Server: nginx/1.13.5

<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.13.5</center>
</body>
</html>

This appears now always and when I just started testings - everything was fine. What does it mean?


#4

That error is saying that you changed the schema definition for __Class from ‘name’ to ‘class_name’, how did you add those Object types to your schema the first time? Manually I’d guess

The correct way to add them would be using the predefined object types, like so…

let schema = [
  TickerSchema,
  Realm.Permissions.Permission,
  Realm.Permissions.User,
  Realm.Permissions.Role
]

As for the error, you are making a destructive change which isn’t allowed. If you are in development just create a new realm and abandon the old one, in production you’d need to migrate.

The 502 errors have been happening quite allot in the past few days, not sure why, you’d need to open a ticket.


#5

I added them like this (as you already wrote):

let schema = [
  TickerSchema,
  Realm.Permissions.Permission,
  Realm.Permissions.User,
  Realm.Permissions.Role,
  Realm.Permissions.Class
]

If I add Realm.Permissions.Class - I got the error about changes in the schema, if not - I got the error about __Class is not presented in realm schema.

Then I tried to create a new realm with the same configuration (before I just “opened” it), and I get this error message:

Failed to transform received changeset: Schema mismatch: '__Class' has primary key 'name' on one side, but primary key 'class_name' on the other

I did not change the code in the realm library, and for sure I can not change the schema on the cloud side. :slight_smile: