0

I'm new to CouchBase, and I'm looking for a solution to scale my social network. Couchbase looks more interesting, specially it's easy to scale features.

But I'm struggling about creating a view for a specific kind of document.

My documents looks like this:

{
"id": 9476182,
"authorid": 86498,
"content": "some text here",
"uid": 41,
"accepted": "N",
"time": "2014-12-09 09:58:03",
"type": "testimonial"
}
{
"id": 9476183,
"authorid": 85490,
"content": "some text here",
"uid": 41,
"accepted": "Y",
"time": "2014-12-09 10:44:01",
"type": "testimonial"
}

What I'm looking for is for a view that would be equivalent to this SQL query.

SELECT * FROM bucket WHERE (uid='$uid' AND accepted='Y') OR (uid='$uid' AND authorid='$logginid')

This way I could fetch all user's testimonials even the ones not approved, if the user who is viewing the testimonials page is the owner of that testimonials page, or if not, show all given users testimonials where accepted is =="Y", plus testimonials not approved yet, but written by the user's who is viewing the page.

If you could give me some tips about this I'll be very grateful.

valter
  • 418
  • 9
  • 24

1 Answers1

0

Unlike SQL you cannot directly pass input parameters into views; however, you can emulate this to some extent by filtering ranges.

While not exactly matching SQL, I would suggest you simply filter testimonials based on the user ID, and then do the filtering on the client side. I am making the assumption that in most cases there will not even be any pending testimonials, and therefore you will not really end up with a lot of unnecessary data.

Note that it is possible to filter this using views entirely, however it would require:

  • Bigger keys OR
  • Multiple views OR
  • Multiple queries

In general it is recommended to make the emitted keys smaller, as this increases performance; so better stick with the above-mentioned solution.

Mark Nunberg
  • 3,551
  • 15
  • 18