1

I've created a very simple development view on my production Couchbase server

function (doc, meta) {
  if (meta.id.indexOf("user:") == 0) emit(meta.id, doc);
}

This view doesn't return any results. Testing the same view on my local couchbase server works fine.

Publishing this view as a production view works fine.

What could be wrong? I'm using Couchbase version: 2.2.0 community edition (build-837)

Lior
  • 7,845
  • 2
  • 34
  • 34

1 Answers1

0

When developing views, Couchbase will only use a subset of data in your bucket for the results. IIRC this is one vBucket's worth of data. It uses a subset of data as some views can be quite large and when developing a new view you do not want to bog down the whole cluster. So while rare, it is possible that when you are running your development view, the subset of data picked up on that one cluster has no matching results. Once that index is promoted to be a production view, i.e. you are done developing it and are ready to use it in prod, then it'll use the whole data set in that bucket.

On a related note, it looks like you are emitting the entire document if I am not mistaken. Depending on your data set and the selectivity of this view on that data, that could get quite expensive as your data grows. So you will have to watch this. Make sure you have enough disk space for this and enough OS RAM (not taken up by Couchbase) to keep as much of that index in memory since it is treated differently than Couchbase objects. Emitting a lot of data can also slow down your rebalances, especially if you are using the default internal settings like index aware rebalances. I do not know your use case obviously, but it might be better to just emit the IDs and then bulk get those IDs or something. This might be one of those situations where can views do this, yes, but should they and is there a better way to solve the same thing. Anyhow, just something to think about.

NoSQLKnowHow
  • 4,449
  • 23
  • 35
  • Thanks for your answer @Kirk. It's very hard to finish developing a view if Couchbase chooses not to return data for it (which I know for fact is there). Are you sure this is the intended behavior? Is this stated anywhere in the docs? Just trying to make sure there's no technical issue here. You note about emitting the entire view is excellent. Thanks – Lior Oct 22 '14 at 22:40
  • Here is the relevant doc on development views. http://docs.couchbase.com/admin/admin/Views/views-development.html It mentions a way to force it to see the full dataset, but I do not recall seeing that as an option in the WebUI. So it might be in the REST API or done through the SDKs. I'll do some more digging and see if I can find out. – NoSQLKnowHow Oct 23 '14 at 15:26
  • It is in the webUI it seems, I just have never used it. In the WebUI there is a button where you can force the development view to be built on your full dataset. Try that and see if you get results. Depending on your data set, it might take a while to build. – NoSQLKnowHow Oct 23 '14 at 16:42
  • I tried it in the web UI. I didn't get results there either. Also, my production database is brand new and still very small. That's why I think there's something else. – Lior Oct 23 '14 at 16:46
  • I will try and do some digging, but cannot promise I'll find anything. How big is the dataset in that cluster where the dev view is not working? I'd be interested to know if this happens in 3.0 community edition as well. More curious than anything. – NoSQLKnowHow Oct 23 '14 at 17:13
  • It's 165mb. Thanks for digging. – Lior Oct 24 '14 at 02:25
  • Is there a way to force a few specific documents to be part of the subset? In my case there are thousands of documents that will not match my condition and less than 1% will (the whole purpose of my view is to dig this type of odd documents). When doing development, looks like the docs CB is choosing are the ones that will not fall in the condition, so I always get empty subset. – L. Holanda Mar 08 '16 at 17:42