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

Simple Composite Key Question

2 replies [Last post]
  • Login or register to post comments
Tue, 10/23/2012 - 09:04
couchbase_user1234
Offline
Joined: 10/22/2012
Groups: None

Does CouchBase support composite keys (not in a view)?

I would like to use CouchBase instead of MS SQL for search functionality. Users search by combinations of a few "keys" but the CouchBase client API suggests that I must use a string for the keys and can use objects for the values.

How should I approach this problem? Should this all be done in a view? If so, what should the normal key be... there is no single unique enough/useful field.

Top
  • Login or register to post comments
Thu, 10/25/2012 - 01:17
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello,

Do not hesitate to provide a concrete example of the type of data you are using in your application. This will help Couchbase forum users to give you precise answers. So let me answer:

You are right a Couchbase key is a single string. So you have different approaches to deal with "composite information". The important thing to keep in mind is that you will design your data based on the way you want to access information from your application.

You can for example create a "complex" key base on the concatenation of strings. This allows you to provide multiple ways to access data using lookups. A good example of this has been documented here:
- http://couchbasemodels.com/patterns/lookup

The other approach, as you said, will be to use Views, to help SQL developers to understand and use views the Couchbase documentation contains the following chapter:
Translating SQL to Map/Reduce

I admit that it is not the same but may be a good start to see how you should adapt your application to move from MSSQL to Couchbase.

Here some interesting chapters to help you design your applications/data:
- Modeling Documents
- Finding Data with Views
- Views & Indexes

Regards
Tug

__________________

Tug
@tgrall

Top
  • Login or register to post comments
Thu, 10/25/2012 - 09:57
couchbase_user1234
Offline
Joined: 10/22/2012
Groups: None

Thanks for those links - especially the lookup pattern one. Unfortunately I don't think it applies here. Below I've come up with a comparable concrete example:

Users want to find info on university courses. However, each university has a different table/schema of courses in MSSQL (not changeable). There are many courses (~1 billion). To find the correct course, the system needs 1. the university and 2. the course id. The course id is only unique in the university context.

Let's say users can search on 1. course name, 2. professor first name, 3. professor last name, 4. course start time, 5. university state. They can also use various predefined (view?) search combinations (the reason the lookup pattern won't work as well).

So, since all we need as a value is the unique Univ/CourseID what I'm thinking is storing KEY: "university,course_id" and VALUE: other (search) fields. I think this technically feasible but it seems wrong to store search terms in the value and the search target in the key. Is this a valid approach/is there a better way?

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