I'm developing a mobile app using Swift
and Realm
database.
I configured Realm Device Sync
and tried to add custom user data
to a cluster I created.
Even though I watched dozens of tutorials about realm permissions
I still can't figure out what's wrong with the in-app permissions
here is the authentication function I am using to add 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
}
}
}
But when I try to create a new user, it successfully creates one. The problem is, when it comes things comes to adding the Custom User Data
it returns an error like this:
Failed to insert document: no rule exists for namespace 'UserAPI.Users'
and when I check the MongoDB logs, I can see the error in more detail:
any help would be appriciated, I'm struggling with this error for 3 days, thanks in advance.