I'm learning Couchbase, now on version 3.x
My doubt is, when should i use a N1QL query vs a View query?
And, are there performance differences between them?
Note: I have a situation:
A Bucket with two document types for my Traveling App: Route and City
A Route doc holds the information about the traveling route and an array of City ids that are part of it, then another doc holds the city's information (each city having its own doc). Example:
//Bucket : "Traveling App"
{
"type" : "route"
"name" : "The Great Adventure",
"cities" : ["234", "h4345", "h42da"]
}
{
"type" : "city",
"name" : "Little Town",
"UID" : "234"
}
When i query for a certain traveling route, should i do a N1QL query or a View query?
Because i would have to first open the Route doc, get the cities array than get each City doc.
And i think this architecture would be best, because some routes can have very few cities and others can have a lot of cities.
N1QL looks promising for your data. Even though it is, as another poster points out, in developer preview, it's worth exploring. You can NEST traveling_app with itself to get all city docs 'nested' with each route:
SELECT r.name, c FROM traveling_app r NEST traveling_app c ON KEYS r.cities;
To get say the city names for a particular route, join the traveling_app with itself using the route's cities as keys:
SELECT c.name as city_name FROM traveling_app r JOIN traveling_app c ON KEYS r.cities WHERE r.name = "The Great Adventure";
These queries will operate the same, regardless of how many cities a route has.