3

I have a couchbase server and I am trying to create some views but it seems that I don't have the full understanding of views concept. I have the two following example documents:

{
  "id": 70,
  "status": 2,
  "updatedAt": "2014-09-04T08:52:29.969Z",
  "createdAt": "2014-09-03T21:32:19.000Z",
  "user1": {
    "id": 33185,
    ....
  },
  "user2": {
    "id": 40838,
    .....
  }
}

{
  "id": 71,
  "status": 4,
  "updatedAt": "2014-09-03T21:33:09.404Z",
  "createdAt": "2014-09-03T21:32:20.000Z",
  "user1": {
    "id": 37126,
    ....
  },
  "user2": {
    "id": 36094,
    .....
  }
}

when I create a view with this map function:

function (doc, meta) {
  if (doc.user1 && doc.user2) {
    emit(doc.id, doc);
  }
}

the first document (with id: 70) is not returned by the view while the second is. I didn't understand why even though both have user1 and user2.

Any help is very appreciated.

Community
  • 1
  • 1
Sami
  • 5,819
  • 1
  • 23
  • 30
  • 2
    Does this happen still if you promote the development design document to be a production? – NoSQLKnowHow Oct 30 '14 at 19:11
  • Tanks @Kirk I am new to Couchbase and I didn't know that development views work only on a subset of the documents, when I tried the view with the full subset it brought all expected documents. – Sami Nov 01 '14 at 09:34
  • You really do not want to emit doc, that will make you indexes massive and kill performance. Instead the view will always return the key of the document, which you can use to get the document using the normal get method. – Paddy Dec 17 '14 at 13:06

2 Answers2

4

You need to promote the document to be a production design document from being a development one. Development design docs only operate on a subset of data.

0

The thing to remember is that Development views are for developing the view itself and only see a subset of data. Once you have it so the view is working the way you want, you promote the view to be a production view so it works against the entire data set.

NoSQLKnowHow
  • 4,449
  • 23
  • 35