no there isn’t a notion of “unique constraint” in Couchbase. However you could use the concept of a “lookup document”: create an additional document which key is a derivative of the field you want to be unique. For example
email::sherlockDOTholmesATmycroftsoftDOTcom would be the lookup document for the following user:
{ "userId": 10041240,
"login": "shomes",
"fname": "Sherlock",
"lname": "Holmes",
"company": "Mycroft Soft",
"email": "sherlock.holmes@mycroftsoft.com"
}
(so, prefix with email::, append the email with all . replaced with DOT and @ replaced by AT => that’s your lookup key)
From there on, if another user wants to register with the same email, use the same procedure to derive the lookup key and try to use the create operation. It will fail because the key already exist, and you then know the registration should be cancelled (thanks, optimistic locking).
Note: I’ve used a different example as yours, because Credit Card information is very sensitive data, and you should do your maximum to avoid storing it in your own system (ALWAYS prefer using the services of a specialized, well-recognized, third party payment provider).
+
=
