我无法打开领域。我的设置有问题。这是应用程序中的代码:
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配置屏幕截图
编辑:用“任务跟踪器”应用中提到的那些替换了“同步”中的“权限”设置,并使其连接起来:
编辑:根据杰伊的建议,配置设置已更改为以下内容。
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?
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] 删除。
我来说两句