Best Practice: Delete and Update Lookup vs View operations

Hi,

I am designing my document schema in couchbase. The user document has follow properties:

USER DOCUMENT

  • user::uuid (couchbase primary key)
  • name
  • email (it’s unique per user)
  • password

as user can change email address at any time I decide to use Lookup instead of Views so I have created another lookup document to prevents duplication of emails:

LOOKUP USER REFERENCE DOCUMENT

  • user::email (couchbase primary key)
  • user::uuid (user reference ID)

This work great when you retrieving or creating (first you try create user reference document to make sure email doesn’t exist) document.

GET
System lookup for user id by email
System get user details by user id

POST
System generate User ID(user::uuid) and user ref ID(user::email)
System create user lookup document (if email already exist system returns 409)
System create user document

But what about UPDATE and DELETE? Is my design correct? Should I use lookups or should I use Views? With lookups I have consistency and performance advantages but on other site I need to do multiple calls for UPDATE and DELETE operations.

DELETING
Admin delete user
System lookup for user id by email
System delete lookup reference document
System delete user document

UPDATE
System lookup for user id by email
System get user details by user id
System check if email address has changed
if YES
System generate new and user ref ID(user::email)
System delete old user lookup document
System create new user lookup document with user ref email ID(user::email)
System update user document

Thanks

I like you’re ref doc approach. As an example, the ODM we have for node.js does this functionality built in, including managing the referential integrity. https://github.com/couchbaselabs/node-ottoman/tree/refactor

Thanks

Todd