I have a custom role which has the following permission and yet I am not able to create this document with that role selected. I am able to create it with server role.
Your query uses a predetermined document ID in the postRef. If a document already exists with that reference, then the create permission is ignored and the write permission would need to be enabled. Still, Create would fail in that situation:
If you really need to create new documents each time, use Create(Collection("posts"), ...), which will create a document with an auto-generated reference.
If you need that reference ahead of the document creation, then you should use NewID() to create a reference that should not collide with any existing reference.
What does the getPostByPostId do? Is it the equivalent of calling Get(Var("postRef"))? If so, the UDF is redundant: calling Create returns the document that it creates:
Hi Ewan, thanks for your response. I have posted the query that I am running in the shell for both server role and my custom role. I of course delete the document with that document ID before running the query. That is how I am able to create this document every time I execute this query in the shell with the server role.
The second part is not redundant as it fetches the other details of the author and community along with the just created post. Though I would probably retire it now, now that I have the user management setup with google auth.
I have however looked at this differently since you pointed me in that direction.
I am able to create the document with both server and custom-role when not specifying the document ID Create(Collection("posts"),
I am able to create the document with only server role when specifying the document ID. Not able to create with custom-role. (I am deleting the document after creating so existing document isn’t the problem) Create(Ref(Collection("posts"), "320709300642120265"),
So does creating document with prefetched document ID require additional permission?