How to make schema field unique?

I want to make the field unique how is that possible on Mongodb Realm schema declaration. I know that _id is unique but i want to have other fields to be unique

The JSON Schema standard is designed to validate the structure of a document, rather than to cross-reference values between multiple documents.

You can ensure that no duplicate keys get persisted in Atlas by adding unique indexes (but, as with the JSON schema), that wouldn’t prevent the client app creating an Object that broke that constraint.

That means that you’ll need some app-side checking. If you need to check for unique values across all partitions (some of which the user can’t access) then you could add a backend Realm Function (that can see all data) that makes the check – your client app can then call that function before adding a new Object to Realm.

I would ask what the use case is? Is this unique for objects in a single partition or for all partitions?

Also, what would the expected bahavior be if you attempt to write an object that had a field value that was not unique? Some kind of error or failure?

And as @Andrew_Morgan mentioned - can you just add client side code to ensure uniqueness - perhaps before even attempting to write? e.g. stop the user from entering a duplicate email address as the user is attempting to enter it.