我已经在谷歌云平台上的虚拟机上使用 docker 容器方法安装了 Realm Object Server。容器正在运行,我可以在浏览器中连接并查看 ROS 页面。我可以使用 Realm Studio 连接到它并添加用户。
我有一个在 Mac 上本地运行的 nodeJS 应用程序,我正尝试使用它登录并写入服务器上的 Realm 。当我运行应用程序时出现错误,返回的用户是一个空对象。不知道我做错了什么。 我是 NodeJS 的新手。
代码:
var theRealm;
const serverUrl = "http://xx.xx.xx.xx:9080";
const username = "xxxx";
const password = "xxxx";
var token = "long-token-for-enterprise-trial";
Realm.Sync.setFeatureToken(token);
console.log("Will log in user");
Realm.Sync.User.login(serverUrl, username, password)
.then(user => {
``
// user is logged in
console.log("user is logged in " + util.inspect(user));
// do stuff ...
console.log("Will create config");
const config = {
schema:[
schema.interventionSchema,
schema.reportSchema
],
sync: {
user: user,
url: serverUrl
}
};
console.log("Will open realm with config: " + config);
const realm = Realm.open(config)
.then(realm => {
// use the realm instance here
console.log("Realm is active " + realm);
console.log("Will create Realm");
theRealm = new Realm({
path:'model/realm_db/theRealm.realm',
schema:[
schema.interventionSchema,
schema.reportSchema
]
});
console.log("Did create Realm: " + theRealm);
})
.catch(error => {
// Handle the error here if something went wrong
console.log("Error when opening Realm: " + error);
});
})
.catch(error => {
// an auth error has occurred
console.log("Error when logging in user: " + error);
});
输出:
Will log in user
Server is running...
user is logged in {}
Will create config
Will open realm with config: [object Object]
TypeError: Cannot read property 'token_data' of undefined
at performFetch.then.then (/pathToProject/node_modules/realm/lib/user-methods.js:203:49)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
TypeError: Cannot read property 'token_data' of undefined
at performFetch.then.then (/pathToProject/node_modules/realm/lib/user-methods.js:203:49)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
错误@user-methods.js:203:49
const tokenData = json.access_token.token_data;
json 是: { 用户 token : { token :'xxxxxxxx', token 数据: { app_id: 'io.realm.Auth', 身份:'xxxxxxx', 盐:'xxxxxxxx', 过期:1522930743, is_admin: false } } };
所以 json.access_token.token_data 是未定义的但是 json. user_token.token_data 不会。
最佳答案
我建议您尝试与 realm studio 的 ROS 连接,因为您也可以检查日志,这将帮助您修复错误。如果您仍然无法修复,那么您可以联系 Realm 支持团队,即使他们帮助我修复了使用 Docker 的 Xamarin Forms 中的 ROS 连接问题。
关于node.js - 无法使用 NodeJs 连接到 Realm 对象服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49449693/