Issue/Scenario:
Some user had their email address updated causing keycloak to generate a new object which in turn created a new user object in mongo. The old keycloak object pertaining to the user was removed by an automated cleaning script.
Root Cause:
This broke the mapping between the old mongo user bson object and the projects bson object, meaning, the user wasn't able to navigate to their projects.
Resolution:
For this instance we'd have to re-map the reference between the 2 mongo collections. We could do this by getting the _id value for the old user bson object, find all the projects owned by this ObjectId and updating those by the new user's ObjectId, as per :
db.projects.aggregate([{ "$match": {"ownerId": {$exists: true, $eq: ObjectId("63f796625d213530a02a5ad8") }}},{ $group: {"id": "$_id", name: {$first:"$name" }}},{"$unset":["ownerId"]},{"$set" : {"ownerId":ObjectId("6324459c527b3129b44289fe")}}])
db.projects.updateMany({"ownerId" : ObjectId("6346aa6364fb33141da22c50")},{"$set" : {"ownerId":ObjectId("6324459c527b3129b44289fe")},{ upsert: false, multi: true})
Substitute the ownerId with the _id value for the old user in $eq: ObjectId("63f796625d213530a02a5ad8")
and with the _id value for the new user in {"$set" : {"ownerId":ObjectId("6324459c527b3129b44289fe")}
Similarly with updateMany, substitute the ownerId with the _id value for the old user in {"ownerId" : ObjectId("6346aa6364fb33141da22c50")}
and and with the _id value for the new user in {"$set" : {"ownerId":ObjectId("6324459c527b3129b44289fe")}
The user should be able to access the projects after modifying this ownership.
Note:
It is recommended that the admins consult Domino Support before executing the update statements in Mongo.
Comments
0 comments
Please sign in to leave a comment.