user1661621
user1661621

Reputation: 797

couchbase per user data approach

having a bit of trouble finding the correct way to model per user data in couchbase and sync up via couchbase mobile for user specific data. In couchdb you have a separate database per user. What is the best approach in couchbase ?

Upvotes: 3

Views: 297

Answers (2)

Jinesh Jain
Jinesh Jain

Reputation: 1242

You can create your documents in that way which can able to ease the retrieve all related entity. e.g.

  1. Create your documents with user_{Guid} consider Guid as your UserID
  2. Make all other related document with this same Guid like credential_{Guid} so when user logged in we can have userID in session and get all information of that user.

Upvotes: 1

user1697575
user1697575

Reputation: 2848

In Couchbase there is no such thing as "user data". Its generic and open for your designs.

Normally when you design your object domain model for Couchbase you would inject metadata in your key structure.

For example: Key for Account: "Acc#123456789" - where prefix "Acc#" is telling about type of the key, and "123456789" adds particular address instance of this key...resulting in the unique key. Similarly if you want to encode associated address to the account, you'd architect the following key: "Acc#123456789#Addr" - where postfix "#Addr" identifies type of the key for address object

Now, if you want to have user specific keys, you just simply inject user identifier into the key value (from the example above):

  • key "Acc#123456789" will transform to "usr#12345#Acc#123456789"
  • key "Acc#123456789#Addr" will transform to "usr#12345#Acc#123456789#Addr"

Read more on Couchbase data modeling here and keys and metadata

Upvotes: 1

Related Questions