I’m trying to use the Realm function to update the user data, When I select the specific user from the Realm function change user
and try to get the current user document the document is null but I can get the document with the system user.
Here is my function
exports = async function updateUserPublicData(arg) {
const cluster = context.services.get('mongodb-atlas');
const collection = cluster.db('user').collection('public');
const userId = context.user.id
const updatedUser = await collection.findOne({ _id: BSON.ObjectId(userId) })
return updatedUser;
};
I use Realm authentication and when the user signed I call the Authentication create trigger function and create a new user document and save the user, using the Realm authentication authId
for user public document id
Sample user public documentation
User public collection rule
{
"roles": [
{
"name": "owner",
"apply_when": {
"_id": "%%user.id"
},
"insert": true,
"delete": true,
"search": true,
"write": true,
"fields": {},
"additional_fields": {}
}
],
"filters": [],
"schema": {
"title": "Public",
"bsonType": "object",
"required": [
"_id"
],
"properties": {
"_id": {
"bsonType": "objectId"
},
"createdAt": {
"bsonType": "date"
},
"updatedAt": {
"bsonType": "date"
},
"name": {
"bsonType": "string"
},
"image": {
"bsonType": "string"
}
}
}
}
For update user function User Authentication
I set Application Authentication
I’m I missing something?