I have groupMemberships object in which docId is a combination of groupId and userId. I made it like that because is easy to scale. Here is a code snippet of how I'm trying to do concatenation I tried many ways but nothing works:
match /comments/{document=**} {
function checkIfHasMembership(groupId, userId) {
// Construct the document path using string concatenation
let groupMembershipPath = 'groupMemberships/' + groupId + userId;
let groupMembershipDoc = get(/databases/$(database)/documents/$(groupMembershipPath)).data;
return groupMembershipDoc.userId == userId;
}
allow read: if true;
allow write: if checkIfHasMembership(resource.data.groupId, request.auth.uid);
}
I tried different way of concatination even with interpolation nothing works.
Strings do have concatenation with +
, according to the API documentation.
The problem is likely how you are building the document path without specifying each path component separately. Try expressing the path of the document like this instead:
let groupMembershipId = groupId + userId;
let groupMembershipDoc = get(/databases/$(database)/documents/groupMemberships/$(groupMembershipId)).data;