Reputation: 43
I am trying to work on restricting people who are able to like the posts on an application built on firebase.
I need to verify if the last element of the array exists. However, I am unable to find the last element present inside array.
I have an array 'Likes' in cloud firestore which has 2 parts - userName and userId
How will I be able to find the last userId present in the array via firestore rules
I have tried below as can be done in python but doesnt work -
request.resource.data.likes[-1].userId
Upvotes: 1
Views: 356
Reputation: 598765
What you call an array, is actually known as a List
object in Firestore security rules. This type indeed does not recognize negative offsets (honestly: most systems I know of don't), but you can get the same by using size
.
So something like:
request.resource.data.likes[request.resource.data.likes.size()-1].userId
Upvotes: 2