无法使用mongodb sync打开Realm

袋鼠克里斯

我无法打开领域。我的设置有问题。这是应用程序中的代码:

var configuration = user.configuration(partitionValue: "user=\(user.id)")
configuration.objectTypes = [User.self]
Realm.asyncOpen(configuration: configuration) { [weak self](userRealm, error) in
                self!.setLoading(false);
                guard error == nil else {
                    fatalError("Failed to open realm: \(error!)").   ///// here was my error before the edit (I changed the Permission Settings in Sync)
                }

错误代码:“致命错误:无法打开领域:错误Domain = io.realm.unknown Code = 89”操作已取消” UserInfo = {Category = realm.basic_system,NSLocalizedDescription =操作已取消,错误代码= 89”

Mongodb Sync配置屏幕截图

Mongodb Sync配置屏幕截图

编辑:用“任务跟踪器”应用中提到的那些替换了“同步”中的“权限”设置,并使其连接起来:

在此处输入图片说明

编辑:根据杰伊的建议,配置设置已更改为以下内容。

var configuration = user.configuration(partitionValue: "\(currentUser.id!)")

这是我对User Collection的Scheme定义:

{
"properties": {
"_id": {
  "bsonType": "string"
},
"_partition": {
  "bsonType": "string"
},
"name": {
  "bsonType": "string"
}
},
"required": [
   "_id",
   "_partition",
   "name"
],
"title": "User"
}

这是我在Xcode中的User类:

class User: Object {
@objc dynamic var _id: String = ""
@objc dynamic var _partition: String = ""
@objc dynamic var name: String = ""
override static func primaryKey() -> String? {
    return "_id"
}
}

EDIT: I got this going to establish a connection by updating the Sync Permissions, so the app does not crash any more. However, now I am getting this message:

Connection to daemon was invalidated
Signup successful!
Log in as user: y
Login succeeded!
2020-10-25...Sync: Connection[1]: Session[1]: client_reset_config = false, Realm exists = false, async open = false, client reset = falseSync: Connection[1]: Session[1]: client_reset_config = false, Realm exists = false, async open = false, client reset = false
2020-10-25...Sync: Connection[1]: Connected to endpoint '13.54.209.90:443' (from '.....:52139')
2020-10-25...Sync: Connection[1]: Reading failed: End of input
2020-10-25...Sync: Connection[1]: Connection closed due to error```

I don't understand that the error "("Failed to open realm: (error!)")" in my above code is not triggered, but then in the log it says that the realm does not exist! So, what's going on here?

EDIT : this is the user table in mongodb, so I created some Users successfully.

在此处输入图片说明

EDIT : This is the log from mongodb

在此处输入图片说明

As we can see the User Id and the Request ID are not the same! I guess that the two IDs should be the same string in order to be authenticated, right??

I am following the Task Tracker app tutorial from the mongodb webpage for Swift to add the user login to my app. What am I missing here?

Jay

As a complete guess, your config string is not correct

var configuration = user.configuration(partitionValue: "user=\(user.id)")

由于分区值解析为

partitionValue: user=Optional("5f1b586f757611faec257d88")

尝试这个

guard let user = your_app.currentUser() else {
    print("no user")
    return
}

guard let userId = user.id else {
    print("no user")
    return
}

var configuration = user.configuration(partitionValue: "user=\(userId)")

更重要的是,您尝试使用的分区值是此字符串

user=5f1b586f757611faec257d88

我认为您真正想要的是使用用户ID

5f1b586f757611faec257d88

那就是我要开始的地方。如果您尝试利用Realm规则,那么类似的方法_partitionKey: "team_id=1234"会起作用,但超出了原始问题的范围(并增加了另一层复杂性-首先使其工作,然后再探索规则)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法迁移已经打开的Realm文件〜Realm〜Android

来自分类Dev

无法打开使用 MongoDB Stitch 上传到 S3 的图像

来自分类Dev

mongodb无法创建/打开锁定文件

来自分类Dev

MongoDB monodump 成功但无法打开存档

来自分类Dev

无法在 MongoDB shell 中打开集合

来自分类Dev

Realm Studio:无法打开领域...无效的顶部数组(参考号:34280,大小:11)

来自分类常见问题

使用Realm Studio打开我的领域文件时出现问题

来自分类Dev

使用Realm Studio打开我的领域文件时出现问题

来自分类Dev

Modal无法使用Django打开

来自分类Dev

无法使用 fso 打开文件

来自分类Dev

终端无法使用热键打开

来自分类Dev

VBA使用Outlook打开Excel无法打开

来自分类Dev

无法使用JavaScript打开<div>打开页面

来自分类Dev

使用Nil无法更新Realm对象

来自分类Dev

无法使用 Realm 对象填充 TableView

来自分类Dev

无法使用pymongo查询Mongodb

来自分类Dev

无法使用pymongo查询Mongodb

来自分类Dev

无法使用boost :: iostreams :: file打开文件

来自分类Dev

无法使用Python打开Visio文档

来自分类Dev

无法使用ufw打开端口

来自分类Dev

使用laravel安装无法打开流

来自分类Dev

无法打开使用dompdf生成的pdf文件

来自分类Dev

使用NodeGit无法打开存储库

来自分类Dev

无法使用fopen(php)打开文件

来自分类Dev

无法打开使用AFNetworking的旧iOS项目

来自分类Dev

无法使用Java打开.jar文件

来自分类Dev

无法使用PIL在Mac上打开图像

来自分类Dev

我似乎无法使用pygame打开图像

来自分类Dev

无法打开使用ITextSharp创建的合并的pdf