【问题标题】:Realm device sync "Action on service 'mongodb-atlas' forbidden: no rules have been configured for this service" error领域设备同步\“禁止对服务\'mongodb-atlas\'执行操作:没有为此服务配置规则\”错误
【发布时间】:2022-08-14 21:42:49
【问题描述】:

我正在使用SwiftRealm 数据库开发移动应用程序。

我配置了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\'

当我检查 MongoDB 日志时,我可以更详细地看到错误:

我的Custom User Data 设置:

和我的应用权限:

任何帮助将不胜感激,我正在为这个错误苦苦挣扎 3 天,在此先感谢。

  • 为了进行测试,请将您的读取和写入权限设置为 true,然后重试。
  • 它也没有用,我不认为问题出在权限上,因为我尝试了有关权限的一切

标签: ios swift mongodb realm realm-database


【解决方案1】:

@GrandSirr - 您是否尝试过设置“用户可以读取和写入所有数据”权限模板(至少用于开发)?

另外,您的实际“用户”集合是什么?在我看来,用户自定义数据应该是一个单独的集合,因为用户自定义数据的大小是有限的。

我的流程 - 使用电子邮件密码登录用户 - 设置数据库触发器以创建具有相关字段的新用户文档,用户稍后可以填写这些字段,例如您的应用程序的“个人资料设置”页面和另一个触发器以在单独的用户自定义数据中创建文档收藏以保存一些权限角色或订阅通知等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-27
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多