Connecting to server and creating a schema but data is not being inserted


#1

I have created a realm database and stored data in it

later, created a realm object server and logged into it.

I am using koa2 with node 7 and connecting to object server. The schema which I passed is being created as table in the object server but the data is not being sent to object server and stored.

import ‘babel-polyfill’
import Koa from ‘koa’;
import KoaRouter from ‘koa-router’;
import bodyParser from ‘koa-bodyparser’;
var fs = require(‘fs’);

var Realm = require(‘realm’);

var router = new KoaRouter();

var app = new Koa();
app.use(bodyParser());

app
.use(router.routes())
.use(router.allowedMethods());
router.post(’/getdata’, async (ctx, next) => {

var rr = ctx.request.body;

const TestSchema = {
    name: 'TestData',
    properties: {
        name: 'string',
        company: 'string',
        phonenumber: 'int',
        device: 'int',
    }
}
let realm = new Realm({ schema: [TestSchema] });

realm.write(() => {
    realm.create('TestData', {
        name: rr.name,
        company: rr.company,
        phonenumber: rr.phonenumber,
        device: rr.device,

    });
});

let userdata = realm.objects('TestData');

console.log(userdata);
// console.log("data inserted");
ctx.body = userdata;

Realm.Sync.User.login('http://192.168.91.129:9080', 'kart**********@gmail.com', '**********', (error, user) => {

    if (!error) {

        console.log("realm conection established--" + user.identity + "---" + user.isAdmin);

        var realm = new Realm({

            sync: {
                user: user,
                url: 'realm://192.168.91.129:9080/~/karthikpc',
            },
            schema: [TestSchema],

        });

realm.write(() => {
    realm.create('TestData', {
        name: rr.name,
        company: rr.company,
        phonenumber: rr.phonenumber,
        device: rr.device,

    });
});
    }
    else
        console.log('Connection error!');
});

});
app.listen(3000);
console.log(“server running on port 3000”);

error

realm conection established–f19fa12f14c44864af5df8268558d6e4—false
Connection error!
Opening Realm file: /home/karthik/Desktop/TodayKoa2/realm-object-server/f19fa12f14c44864af5df8268558d6e4/realm%3A%2F%2F192.168.91.129%3A9080%2F%7E%2Fkarthikpc
Connection[1]: Session[1]: Starting session for ‘/home/karthik/Desktop/TodayKoa2/realm-object-server/f19fa12f14c44864af5df8268558d6e4/realm%3A%2F%2F192.168.91.129%3A9080%2F%7E%2Fkarthikpc’
Connection[1]: Resolving ‘192.168.91.129:9080’
Connection[1]: Connecting to endpoint ‘192.168.91.129:9080’ (1/1)
Connection[1]: Connected to endpoint ‘192.168.91.129:9080’ (from ‘192.168.91.124:52032’)
Connection[1]: Session[1]: Sending: BIND(server_path=’/f19fa12f14c44864af5df8268558d6e4/karthikpc’, signed_user_token_size=629, need_file_ident_pair=0)
Connection[1]: Session[1]: Sending: IDENT(server_file_ident=1, client_file_ident=2, client_file_ident_secret=7738334209645177565, scan_server_version=1, scan_client_version=2, latest_server_version=1, latest_server_session_ident=2861083039225782877)
Closing Realm file: /home/karthik/Desktop/TodayKoa2/realm-object-server/f19fa12f14c44864af5df8268558d6e4/realm%3A%2F%2F192.168.91.129%3A9080%2F%7E%2Fkarthikpc
Connection[1]: Session[1]: Sending: UNBIND


#2

@karthikanumula what versions of realm-js and realm object server are you using? is this on an ubuntu server or on your local mac osx?


#3

realm js 1.8.2 latest version
realm object server v1.8.1
ubuntu 16.04


#4

@ianward can u please help me with this. Is there any solution , please suggest a way to do it .

FYI: realm js 1.8.2 latest version
realm object server v1.8.1
ubuntu 16.04
I am using koa2 with node 7


#5

@karthikanumula Can you try using node6.10 please? Does the app work without using koa? ie. try just writing dummy data in manually no from a rest endpoint