Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

Document Design Question in regards to Operations Performance

1 reply [Last post]
  • Login or register to post comments
Fri, 04/27/2012 - 08:58
elemon
Offline
Joined: 04/20/2012
Groups: None

Hello everyone!
I am new to this forum and have been very intrigued by Couchbase.

I know that from database to database, operation (writes, reads, updates) performance vary.
Depending on this, I believe that it is necessary that one's data scheme is appropriate for the db.

With this I have a data schema question:

I have a Collection of Events
Event Pages have certain restrictions on them:
1. All users can see EventPublic
2. All invitees can see EventPrivateGroup
3. Only owner can see EventPrivate

EventPages (contain a "Wall")
{ Wall : {"UserName" : "Message", "UserName2" : "Message2"}}
--(Thus, Walls will need an update as well)

If I want my method to be like this (Java Client API) getVisibleEvents(String userId);

My question is the following: (From broad to specific)
1. How should I structure my keys/documents so that make my reads/writes/updates will be most optimized.
2. Since there is a getBulk, but no bulkUpdates or bulkWrites, does this mean that designing for gets and making joins after retrieving it is better?

Thanks so much for your help! I'm looking forward to using this product in my current projects!

Elizabeth~

Top
  • Login or register to post comments
Mon, 05/07/2012 - 06:49
BigBlueHat
Offline
Joined: 01/28/2011
Groups: None

Good questions, Elizabeth.

For your first question, you might consider breaking your "EventPages" document into multiple documents and using a MapReduce View to get the list of entries. This would also allow you to order the wall posts by more things than username.

In a refactored case, you'd have an EventPage document with a unique ID (ex: "eventpage123", and then "child" documents with similar IDs (ex: "eventpage123_post").

eventpage123 would look like this:

{"_id": "eventpage123",
 "type": "eventpage",
 "title": "name of event"}

A "post" document (eventpage123_post) might look similar to:

{"_id": "eventpage123_post",
 "type": "eventpost",
 "username": "UserName2",
 "message": "Message2",
 "created": "1336395815"}

Your MapReduce would then look something like:

function(doc) {
  if (doc.type === "eventpage") {
    emit([doc._id], doc);
  } else if (doc.type === "eventpost") {
    emit([doc._id.split("_")[1], doc.created], doc);
}

When you request that view, you can include the ID of the EventPage doc as the startkey and then [ID, {}] as the endkey:
/bucket/_design/eventpages/_view/event_wall?startkey=["eventpage123"]&endkey=["eventpage123",{}]

That should give you the EventPage doc + each of the EventPagePost documents. You can then combine them how you'd like on the client-side.

As far as bulk updating goes, it's best to use one of our SDKs that can optimize which node writes are written to based on availability.

Hope that helps, Elizabeth,
Benjamin

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker