I need to join between bucket and view in couchbase by n1ql .
It's possible ?
Second , the join query work between bucket keys and any attribute and can not work between attribute and attribute (like foreign key) , right ?
Thanks .
Currently, JOINs between a bucket and a map-reduce view are not supported. If you can put the contents of your view into another bucket, you can JOIN between buckets.
Related
I just started Couchbase.
I would like to find a way to query couchbase to get all buckets like
Select * from tab;
USE <DB NAME>
and retrieve all views as they are faster to pull the data from N1Q1.
select name from system:keyspaces;
Gives all the buckets. For view definitions you need to use #Matthew Groves suggestions.
You can get a list of buckets with N1QL: SELECT r.name FROM system:keyspaces r;
There is no way that I know of to query for a list views with N1QL itself.
You can use the REST API:
To get a list of design docs (which contain views): check out GET /pools/default/buckets/<bucket.name>/ddocs
For more details, check out the documentation:
Getting Views Information
System Keyspaces
I am new to Couchbase noSql database.
I am trying to create a view, i want this view should give result as below SQL query.
SELECT * FROM Employee e WHERE e.name = "DESM%" AND e.salary < 1000 ORDER BY e.id desc
Any suggestion is very appreciated.
If you look at existing beer samples in Couchbase (it comes with it), you will find views defined there. In admin console you can run a view. Notice when you run a view you can provide filtering criteria and sort order for the result...that might be an equivalent for your SQL like functionality. Read more on Views and Indexes
yet another option is to use Couchbase v3 that comes with its own N1QL query language that can serve as another alternative. You can try it out online here.
We all know that using the Eloquent with('relation') function is not doing a JOIN , but it's making another query to get the relationship.
Is there a way to make a single query using JOIN so we can reduce our MySQL queries ?
As far as I know it's not possible to use JOIN when using Eloquent objects. This is how Eloquent work - it doesn't use joins, it uses separate queries to get related data. So if you want to use joins, you won't be able to use Eloquent objects.
You could create a VIEW in database, and then, create a model in your app. Updated data in VIEW is automatically updated in the related tables. Could be a workaround.
Yeah something like this if you want to do a left join ( use ->join() for a simple inner join)
$query = DB::table('product');
$query->leftJoin('user', 'product.seller_id', '=','user.user_id');
return $query->get();
See the query builder docs for further details: http://laravel.com/docs/4.2/queries#joins
I will store, in couchbase, something like this:
key: foo
value: {
some_id => bar,
/* other fields */
}
for me, is easy find the value, using the key 'foo', but how I can find the key 'foo' using the 'some_id' bar (and it can returns more than one result)?
I was reading about views + where clause, it is the only way?
Besides Couchbase views (as you mentioned), as of Couchbase version 3.x you will have N1QL query language. You can specify "where" condition to select your json objects without having any views in place.
So as per your example, you should be able issue a query like that:
SELECT *
FROM your_bucket_name
WHERE some_id = 'bar'
Try out N1QL tutorial
Another way could be to utilize Couchbase integration with ElasticSearch and perform search query in ES engine that will return you all keys it found based on your search criteria.
I'm currently practicing using Sphinx, I've not far off done much, except the configuration what I'm trying to do. The sql_query key is leaving me somewhat confused what to put there, I read in the Sphinx documentation of sql_query but it doesn't seem to clear my mind from knowing what to do since I have many SELECTs in my web application, and I want to use Sphinx for my search and the SQL is often changed (upon user search filtering).
As of my search using MySQL, I want to integrate Sphinx to my web application, if the sql_key is not optional, do I have to expect to put the whole search SQL query into that field or do I pick out the necessary fields from tables to start a reindex?
Can someone point me to the right direction so I can get things going well with Sphinx and my web application.
sql_query is mandatory , it's run by sphinx to get the data you want to be indexed from mysql . You can have joins , conditions etc. , must be a valid sql query . You should have something like "SELECT id ,field1,field2,fieldx from table" . id must be a primary id .Each row returned by this query is considered a document ( which is returned by sphinx when you search ) .
If you have multiple tables ( that are very different by meaning - users , articles etc.) - you need to create an index for each .
Read tutorials from here : http://sphinxsearch.com/info/articles/ to understand how sphinx works .
You can create a sql query to get union set of records from the Database. If you do multiple table joining and query to select the best result set, you can do it with Sphinx too.
You may run into a few trouble with your existing table structure in the database.
Like :
Base table does not have integer primary key field
Create a new table which has two fields. One for the integer id field and the other field to hold the primary key of the base table. Do an inner join with that table and select the id field from that table.
Eg. SELECT t1.id, t2.name, t2.description, t2.content FROM table_new t1 INNER JOIN table_2 t2 WHERE t1.document_id = t1.thread_id INNER JOIN REST_OF_YOUR_SELECT_QUERY
The ta.id is for Sphinx search engine to do its internal indexing.
You filter data by placing WHERE clause and filtering
You can do that in Sphinx by setting filters dynamically based on the conditions.
You select and join different tables to get results
This also can be done by setting different sources and indexes based on your requirements.
Hope this would help you to get an understanding what you need to add and modify to start thinking how Sphinx search engine can be configured to your requirements. Just come here again if your need more help.