Custom User Data - failed to update: insert not permitted


I am trying to insert a document in Custom User Data in App Services
I get error "failed to update: insert not permitted.
Is there any documentation about where to check access rights?
Should I look in Rules in AppService/Data Access ? Or more places?

My Collection has rules:
Document permission: Insert Delete Search
Field permissions: Read: All Write:All
Id: userId

Development Mode is on

Swift code:

        let userId = AnyBSON(mongoDBApp.currentUser!.id)
                    ["userId": userId,
                             "userName": uName,
                             "userLastName": uLastName,
                             "userEmail": uEmail,
                             "userPhone": uPhone
                ) { (result) in
                    switch result {
                    case .failure(let error):
                        print("Failed to update: \(error.localizedDescription)")
                    case .success(let updateResult):                       
                        print("worked: ")


A comment and then a couple of questions;

First, and I am sure you know, this is not a good idea


optionals should be safely handled… they are optionals and could be nil. It may be fine in this case but just mentioning it.

Let’s eleminate some simple things first:

Is the userId valid?

Is the code called in the closure following an app.login or some time later?

Did you check the App Users section in the console to ensure that the field you’re using to map the data matches the structure in the question? It appears to be but making sure.

How is the collection defined?