Error due to not having update permissions as a user

Hi all,

I’m running into the following error when trying to update a User document:

index.ts:32 Uncaught (in promise) Error: reason="role \"default\" in \"maintenance-tracker.User\" does not have update permission for document with _id: 6286bc0194c80f7c64c60124: could not validate document: \n\t_id: Invalid type. Expected: type: undefined, bsonType: objectId, given: [string mixed]"; code="SchemaValidationFailedWrite"; untrusted="update not permitted"; details=map[]

I’m not sure what this means. I do not have trouble updating any other documents. Why would updating this document lead to issues? Does anyone have any tips on figure out what is going on? I’m quite new to this so I’d appreciate some guidance.

The difference between the User documents and other documents is that I create User documents using a function which is triggered whenever a new user signs up.

With the help of SchemaValidationFailedRead on GraphQL I resolved the issue.

It apparently was related to the User document being generated by a function within realm, the function being:

exports = async function createNewUserDocument({user}) {
  const cluster = context.services.get("mongodb-atlas");
  const users = cluster.db("maintenance-tracker").collection("User");
  return users.insertOne({
    _id: user.id,
    id: user.id.toString(),
    _partition: `user=${user.id}`,
    name: user.data.email,
    // canReadPartitions: [`user=${user.id}`],
    // canWritePartitions: [`project=${user.id}`],
    // memberOf: [
    //   {"name": "My Project", "partition": `project=${user.id}`}
    // ],
  });
};

the id field is here created as a string, but in the schema was denoted as an ObjectId.

I was too focused on the permission part of the error message, and not the validation error :slight_smile:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.