Hi, MongoDB community! I would like to implement a feature in my Realm app that allows users to share a document using a public link containing a secret string (similar to apps like Dropbox). The user that receives the link shouldn’t need to register, so they are authenticating anonymously.
How can I set up query roles for this use case? The examples in the documentation always use the %%user
variable do detemine if a user is allowed to access a document. Essentially, I would like to set the role based on some additional value provided by the user (the secret string), not based on the user’s identity or some value stored in the user document. An “Apply When” expression for this role could look like this:
{
"share_secret": "<value provided in the request>"
}
Is there a way to pass additional values like this? Can I add restrictions on what the user can query so that share_secret
must always be included? For example, I would like to prevent users from querying any document because they could get a document that they are not authorized to read:
collection.findOne({});
But I want to allow them to do this:
collection.findOne({ share_secret: "abcdefg" });