0

I have the following documents stored in my Couchbase DB:

{
  name:'first document',
  document_props:['final','received','sent']
}

{
  name:'second document',
  document_props:['final','sent']
}

Now I want to list all documents in which documents_props has final and received. Suppose I need this for final, received, sent. What can I do to facilitate this supposing those properties are not fixed (are free text)?

My current though is to fetch all and evaluate within the application, but this will be really hard work since the database is growing really fast.

Francisco Spaeth
  • 23,493
  • 7
  • 67
  • 106

1 Answers1

0

What you have to do here, is to create an index that contains all the "props". To create an index with Couchbase you have to create a view; this view will be like:

function (doc, meta) {
  if (doc.document_props) {
    for (i in doc.document_props ) {
      emit(doc.document_props[i]);
    }
  }
}

Then you can call the view with the proper key that will be the value in the array. For example :

&key="sent"

or &keys=["sent","final"]

You can call the view from your application using the proper SDK (Java, .Net, PHP, ... dunno which one you are using)

More of views: - http://www.couchbase.com/docs/couchbase-manual-2.1.0/couchbase-views.html

Tug Grall
  • 3,410
  • 1
  • 14
  • 16