Realm Role check duplicate document

Good evening everyone, I am in trouble on this issue:
I have a collection where each document has two fields namely “userId” and “surname”.

I would like to create a rule that checks if when creating a new document there is already another document with the same userId.
So that you can never create two documents with the same userId. How can I do? How can I access the documents of the collections in realm?