【发布时间】:2022-08-14 21:42:49
【问题描述】:
我正在使用Swift 和Realm 数据库开发移动应用程序。
我配置了Realm Device Sync 并尝试将custom user data 添加到我创建的集群中。
尽管我看了几十篇关于realm permissions的教程,但我仍然无法弄清楚应用内权限出了什么问题
这是我用来添加Custom User Data的身份验证功能
func login() {
isLoading = true
errorMessage = nil
let credentials = Credentials.emailPassword(email: username, password: password)
DispatchQueue.main.async {
app.login(credentials: credentials) { [weak self] result in
switch (result) {
case .failure(let error):
print(String(describing: error))
self?.errorMessage = error.localizedDescription
case .success(let user):
if user.customData.isEmpty {
let client = user.mongoClient(\"mongodb-atlas\")
let database = client.database(named: \"UserAPI\")
let collection = database.collection(withName: \"Users\")
// Insert the custom user data object
let customUserData: Document = [
\"_id\": AnyBSON(user.id),
\"email\": .string(self!.email),
\"province\": .string(self!.province),
\"_partition\": .string(user.id)
]
collection.insertOne(customUserData) {result in
switch result {
case .failure(let error):
print(\"Failed to insert document: \\(error.localizedDescription)\")
case .success(let newObjectId):
print(\"Inserted custom user data document with object ID: \\(newObjectId)\")
}
}
}
}
self?.isLoading = false
}
}
}
但是当我尝试创建一个新用户时,它成功创建了一个。问题是,当涉及到添加 Custom User Data 时,它会返回如下错误:
Failed to insert document: no rule exists for namespace \'UserAPI.Users\'
任何帮助将不胜感激,我正在为这个错误苦苦挣扎 3 天,在此先感谢。
-
为了进行测试,请将您的读取和写入权限设置为 true,然后重试。
-
它也没有用,我不认为问题出在权限上,因为我尝试了有关权限的一切
标签: ios swift mongodb realm realm-database