I am working with MongoDB Remote Access - iOS SDK to retrieve and (attempt to) insert documents.
At the moment when we authenticate using the standard MongoDB Realm authentication
let creds = Credentials.emailPassword(email: username, password: password)
app.login(credentials: creds) { result in
we can retrieve data using the remote access functions like this
let client = app.currentUser!.mongoClient("some-client-db-atlas")
let database = client.database(named: "my-database")
let collection = database.collection(withName: "MyCoolCollection")
let whichPartition = "CoolPartition"
collection.find(filter: ["_partitionKey": AnyBSON(whichPartition)], { (result) in
And the data is fetched and returns correctly.
However, inserting/writing isn’t working
let myData = [
("key0", AnyBSON(stringLiteral: "value0")),
("key1", AnyBSON(stringLiteral: "value1"))
]
let myDoc = Document(uniqueKeysWithValues: myData)
collection.insertOne([myDoc], { results in
print(results)
})
results in an error
failure(Error Domain=realm::app::ServiceError Code=-1 “insert not permitted”
It’s possible (?) that we need to create a separate user in the Realm Console Atlas->Database Access and Network Access sections based on this post and then try a separate login/auth
let username = "UserA"
let password = "kaijas09ajadjjad"
let creds = Credentials.emailPassword(email: username, password: password)
app.login(credentials: creds, { result in
print(result)
})
But we get an invalid email/password error.
I see that inserting is not support on Data Lake but that’s not applicable to our situation.
What’s the correct process to make this work so we can insert?