I sort of got it to work as I needed to include all data not the changed data, however why do I need to wrap everything in BSON? And what is the proper way to wrap the ObjectID (companyId)?
let client = user.mongoClient("mongodb-atlas")
let database = client.database(named: "AltoProDev0")
let collection = database.collection(withName: "User")
let values: [String: AnyBSON] = [
"_partition" : AnyBSON(stringLiteral: "user=\(user.id)"),//Question do we need this line
"name" : AnyBSON(stringLiteral: self.preferenceProfileEmail),
"companyId" : AnyBSON(string: self.preferenceProfileCompanyId),
"firstName": AnyBSON(stringLiteral: self.preferenceProfileFirstName),
"lastName": AnyBSON(stringLiteral: self.preferenceProfileLastName),
"title": AnyBSON(stringLiteral: self.preferenceProfileTitle),
"phone": AnyBSON(stringLiteral: self.preferenceProfileContactNumber)
]
collection.updateOneDocument(
filter: ["_id": AnyBSON(stringLiteral: user.id)],
update: values
) { (result) in
switch result {
case .failure(let error):
print("Failed to update: \(error.localizedDescription)")
return
case .success(let updateResult):
print("Matched: \(updateResult.matchedCount), updated: \(updateResult.modifiedCount)")
}
}