You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Terry Brownell <te...@trinitypower.com> on 2010/10/15 01:00:24 UTC
Cooking Views
Hi, attempting to port my semantic network DB to CouchDB, but I'm not
grokking the more complicated views, and in particular passing variables.
Looking for a cookbook recipe for creating a view (against the documents
below), that...
- Selects all documents where "isa" = "bird", that has a nemesis, and color
is a variable ie: all yellow?
{
"_id": "tweety",
"isa": "bird",
"_rev": "3-d085e60568133d80a96cd735c6c306f6",
"color": "Yellow",
"nemesis": "Sylvester"
}
{
"_id": "Sweetie Pie",
"isa": "bird",
"_rev": "3-d085e60568133d80a96cd735c6c306f6",
"color": "Yellow"
}
{
"_id": "Woody",
"isa": "bird",
"_rev": "3-d085e60568133d80a96cd735c6c306f6",
"color": "Blue",
"nemesis": "Buzz Buzzard"
}
Thanks
Re: JavaScript and CouchDB
Posted by "Tyler Gillies @tylergillies" <ty...@pdxbrain.com>.
On Fri, Nov 5, 2010 at 12:44 PM, Mark Essel <me...@gmail.com> wrote:
> I was thinking about analytics stuff today. I made the false assumption
> that all
> interaction/access could easily be tracked by turning on a flag. The lack
> of
> analytics is a pretty severe limitation as to how effective a couch app can
> be.
What do you mean by 'analytics'? There is logging.
>
> My brain still retracts in horror at the anatomy of couchapps after a
> couple of
> months :(
>
> http://messel.posterous.com/looking-over-a-distributed-chat-client-with-i
>
>
>
I think the anatomy is a fair trade-off for the scalability of running an
entire application stack directly from the database
--
*http://eepurl.com/bwk91*
Re: JavaScript and CouchDB
Posted by Mark Essel <me...@gmail.com>.
I was thinking about analytics stuff today. I made the false assumption that all
interaction/access could easily be tracked by turning on a flag. The lack of
analytics is a pretty severe limitation as to how effective a couch app can be.
My brain still retracts in horror at the anatomy of couchapps after a couple of
months :(
http://messel.posterous.com/looking-over-a-distributed-chat-client-with-i
Re: JavaScript and CouchDB
Posted by Mikeal Rogers <mi...@gmail.com>.
You can't do cross domain POST without proper Access Control headers which
we don't support. I sent an email to the dev list recently about adding
support but it hasn't gone anywhere yet.
JSONP can be enabled for GET requests. Browser won't let you do POST or PUT.
-Mikeal
On Fri, Oct 15, 2010 at 5:11 PM, Tracy Flynn
<co...@thisonejustforme.com>wrote:
> Does 'disable by default' mean it's disabled in the default configuration
> but could be turned on if the configuration/compilation option is known? Or
> that it's simply not available?
>
> If it's truly disabled, then the only solution I can see is to introduce a
> proxy that allows a JSON Post (with appropriate security) and then turn
> around and do the appropriate operations on CouchDB using permitted HTTP
> operations.
>
> I'm thinking my way around an associated issue. Some of the feeds I'm
> supporting with CouchDB are paid, some are public. The only way I've so far
> figured out to protect the 'for pay' feeds and provide metering is to
> introduce a proxy in front of CouchDB to perform those functions.
>
>
> On Oct 15, 2010, at 8:01 PM, Mikeal Rogers wrote:
>
> > This is standardized as JSONP which we disable by default because of
> > security implications. This only works for GET, doesn't work for PUT.
> >
> > On Fri, Oct 15, 2010 at 4:58 PM, Tracy Flynn
> > <co...@thisonejustforme.com>wrote:
> >
> >> Fabio
> >>
> >> You might consider the work-around offered by jQuery 1.4.x to the
> >> same-origin problem.
> >>
> >> In a nutshell, they package all Ajax-like requests as a request for a
> >> resource - think image or javascript file - which does NOT have the
> >> limitations of the same-origin policy - and then 'unpack' the result and
> >> make it available to the client as if the 'Ajax-like' request had been
> >> issued directly.
> >>
> >>
> >> A fragment like the following does the trick
> >>
> >>
> >> <html>
> >>
> >> <head>
> >> <title>JSON Call Test Page</title>
> >> <script type="text/javascript" src="
> >> http://localhost:8080/javascripts/jquery-1.4.2.min.js"></script>
> >> <script type="text/javascript" src="
> >> http://localhost:8080/javascripts/json2.min.js"></script>
> >> </head>
> >> <body>
> >>
> >> <script type="text/javascript">
> >> $(document).ready(function() {
> >> $.getJSON("http://localhost:8080/some.js" ,
> >> function(json){
> >>
> $("#somelement").html(json.some_variable_containing_html);
> >> $("#somelement").show();
> >> }
> >> )
> >> });
> >>
> >> </script>
> >> </body>
> >> </html>
> >>
> >>
> >> The call that services the 'some.js' request just needs to return
> whatever
> >> JSON data you want the call to return. Since it's requesting a resource,
> and
> >> not really making an Ajax call - all is well.
> >>
> >> If HTML isn't what you want, you could pass back Javascript embedded in
> a
> >> JSON structure, and then evaluate the result. I've done that
> successfully
> >> too.
> >>
> >> Works like a charm where I've used the facility.
> >>
> >> Tracy
> >>
> >>
> >> On Oct 15, 2010, at 2:41 PM, Paul Davis wrote:
> >>
> >>> You'll need to read up on the Same Origin Policy:
> >>>
> >>> http://en.wikipedia.org/wiki/Same_origin_policy
> >>>
> >>>
> >>> On Fri, Oct 15, 2010 at 2:34 PM, Fabio Batalha C Santos Santos
> >>> <fa...@yahoo.com.br> wrote:
> >>>> Hello everybody,
> >>>>
> >>>> I'm newby in couchDB.
> >>>>
> >>>>
> >>>> I'm trying to develop a "Google Analytics" like applications storing
> >> access log
> >>>> metadata in a CouchDB database. Take a look at
> >>>>
> http://github.com/fabiobatalha/Analytics---CouchDB/tree/master/logger/
> >>>>
> >>>> The idea is:
> >>>>
> >>>> Create a logger JavaScript that will be responsible to register all
> >> accesslog
> >>>> metadata in a CouchDB database. It works like the ga.js Google
> Anaytics.
> >> In the
> >>>> bottom of each page will hava a call to a JavaScript function that
> will
> >> make use
> >>>> of couch.js functions to register logaccess metadata in CouchDB
> >>>>
> >>>> The problem:
> >>>>
> >>>> I'm trying to make use of the couch.js script but the couch.js on
> works
> >> if the
> >>>> request is made from the same host and port were the CouchDB is
> >> installed.
> >>>> Instead of it, my application is in a different host. How can I
> >> configure the
> >>>> connection to the couchDB using the couch.js
> >>>>
> >>>>
> >>>> Thanks in advance.
> >>>> Fabio Batalha
> >>>>
> >>>>
> >>>>
> >>>>
> >>
> >>
>
>
Re: JavaScript and CouchDB
Posted by Tracy Flynn <co...@thisonejustforme.com>.
Nils,
Thanks.
There's always something to be said for actually reading a configuration file (at least once) when I start in with new software!
Tracy
On Oct 28, 2010, at 4:34 AM, Nils Breunese wrote:
> Tracy Flynn wrote:
>
>> Does 'disable by default' mean it's disabled in the default configuration but could be turned on if the configuration/compilation option is known? Or that it's simply not available?
>
> It's available. On older versions of CouchDB it was enabled by default and since 1.0.0 you need to set allow_jsonp to true in your local.ini: http://wiki.apache.org/couchdb/Breaking_changes#Changes_Between_0.11.0_and_1.0.0
>
> Nils.
> ------------------------------------------------------------------------
> VPRO
> phone: +31(0)356712911
> e-mail: info@vpro.nl
> web: www.vpro.nl
> ------------------------------------------------------------------------
Re: JavaScript and CouchDB
Posted by Nils Breunese <N....@vpro.nl>.
Tracy Flynn wrote:
> Does 'disable by default' mean it's disabled in the default configuration but could be turned on if the configuration/compilation option is known? Or that it's simply not available?
It's available. On older versions of CouchDB it was enabled by default and since 1.0.0 you need to set allow_jsonp to true in your local.ini: http://wiki.apache.org/couchdb/Breaking_changes#Changes_Between_0.11.0_and_1.0.0
Nils.
------------------------------------------------------------------------
VPRO
phone: +31(0)356712911
e-mail: info@vpro.nl
web: www.vpro.nl
------------------------------------------------------------------------
Re: JavaScript and CouchDB
Posted by Tracy Flynn <co...@thisonejustforme.com>.
Does 'disable by default' mean it's disabled in the default configuration but could be turned on if the configuration/compilation option is known? Or that it's simply not available?
If it's truly disabled, then the only solution I can see is to introduce a proxy that allows a JSON Post (with appropriate security) and then turn around and do the appropriate operations on CouchDB using permitted HTTP operations.
I'm thinking my way around an associated issue. Some of the feeds I'm supporting with CouchDB are paid, some are public. The only way I've so far figured out to protect the 'for pay' feeds and provide metering is to introduce a proxy in front of CouchDB to perform those functions.
On Oct 15, 2010, at 8:01 PM, Mikeal Rogers wrote:
> This is standardized as JSONP which we disable by default because of
> security implications. This only works for GET, doesn't work for PUT.
>
> On Fri, Oct 15, 2010 at 4:58 PM, Tracy Flynn
> <co...@thisonejustforme.com>wrote:
>
>> Fabio
>>
>> You might consider the work-around offered by jQuery 1.4.x to the
>> same-origin problem.
>>
>> In a nutshell, they package all Ajax-like requests as a request for a
>> resource - think image or javascript file - which does NOT have the
>> limitations of the same-origin policy - and then 'unpack' the result and
>> make it available to the client as if the 'Ajax-like' request had been
>> issued directly.
>>
>>
>> A fragment like the following does the trick
>>
>>
>> <html>
>>
>> <head>
>> <title>JSON Call Test Page</title>
>> <script type="text/javascript" src="
>> http://localhost:8080/javascripts/jquery-1.4.2.min.js"></script>
>> <script type="text/javascript" src="
>> http://localhost:8080/javascripts/json2.min.js"></script>
>> </head>
>> <body>
>>
>> <script type="text/javascript">
>> $(document).ready(function() {
>> $.getJSON("http://localhost:8080/some.js" ,
>> function(json){
>> $("#somelement").html(json.some_variable_containing_html);
>> $("#somelement").show();
>> }
>> )
>> });
>>
>> </script>
>> </body>
>> </html>
>>
>>
>> The call that services the 'some.js' request just needs to return whatever
>> JSON data you want the call to return. Since it's requesting a resource, and
>> not really making an Ajax call - all is well.
>>
>> If HTML isn't what you want, you could pass back Javascript embedded in a
>> JSON structure, and then evaluate the result. I've done that successfully
>> too.
>>
>> Works like a charm where I've used the facility.
>>
>> Tracy
>>
>>
>> On Oct 15, 2010, at 2:41 PM, Paul Davis wrote:
>>
>>> You'll need to read up on the Same Origin Policy:
>>>
>>> http://en.wikipedia.org/wiki/Same_origin_policy
>>>
>>>
>>> On Fri, Oct 15, 2010 at 2:34 PM, Fabio Batalha C Santos Santos
>>> <fa...@yahoo.com.br> wrote:
>>>> Hello everybody,
>>>>
>>>> I'm newby in couchDB.
>>>>
>>>>
>>>> I'm trying to develop a "Google Analytics" like applications storing
>> access log
>>>> metadata in a CouchDB database. Take a look at
>>>> http://github.com/fabiobatalha/Analytics---CouchDB/tree/master/logger/
>>>>
>>>> The idea is:
>>>>
>>>> Create a logger JavaScript that will be responsible to register all
>> accesslog
>>>> metadata in a CouchDB database. It works like the ga.js Google Anaytics.
>> In the
>>>> bottom of each page will hava a call to a JavaScript function that will
>> make use
>>>> of couch.js functions to register logaccess metadata in CouchDB
>>>>
>>>> The problem:
>>>>
>>>> I'm trying to make use of the couch.js script but the couch.js on works
>> if the
>>>> request is made from the same host and port were the CouchDB is
>> installed.
>>>> Instead of it, my application is in a different host. How can I
>> configure the
>>>> connection to the couchDB using the couch.js
>>>>
>>>>
>>>> Thanks in advance.
>>>> Fabio Batalha
>>>>
>>>>
>>>>
>>>>
>>
>>
Re: JavaScript and CouchDB
Posted by Mikeal Rogers <mi...@gmail.com>.
This is standardized as JSONP which we disable by default because of
security implications. This only works for GET, doesn't work for PUT.
On Fri, Oct 15, 2010 at 4:58 PM, Tracy Flynn
<co...@thisonejustforme.com>wrote:
> Fabio
>
> You might consider the work-around offered by jQuery 1.4.x to the
> same-origin problem.
>
> In a nutshell, they package all Ajax-like requests as a request for a
> resource - think image or javascript file - which does NOT have the
> limitations of the same-origin policy - and then 'unpack' the result and
> make it available to the client as if the 'Ajax-like' request had been
> issued directly.
>
>
> A fragment like the following does the trick
>
>
> <html>
>
> <head>
> <title>JSON Call Test Page</title>
> <script type="text/javascript" src="
> http://localhost:8080/javascripts/jquery-1.4.2.min.js"></script>
> <script type="text/javascript" src="
> http://localhost:8080/javascripts/json2.min.js"></script>
> </head>
> <body>
>
> <script type="text/javascript">
> $(document).ready(function() {
> $.getJSON("http://localhost:8080/some.js" ,
> function(json){
> $("#somelement").html(json.some_variable_containing_html);
> $("#somelement").show();
> }
> )
> });
>
> </script>
> </body>
> </html>
>
>
> The call that services the 'some.js' request just needs to return whatever
> JSON data you want the call to return. Since it's requesting a resource, and
> not really making an Ajax call - all is well.
>
> If HTML isn't what you want, you could pass back Javascript embedded in a
> JSON structure, and then evaluate the result. I've done that successfully
> too.
>
> Works like a charm where I've used the facility.
>
> Tracy
>
>
> On Oct 15, 2010, at 2:41 PM, Paul Davis wrote:
>
> > You'll need to read up on the Same Origin Policy:
> >
> > http://en.wikipedia.org/wiki/Same_origin_policy
> >
> >
> > On Fri, Oct 15, 2010 at 2:34 PM, Fabio Batalha C Santos Santos
> > <fa...@yahoo.com.br> wrote:
> >> Hello everybody,
> >>
> >> I'm newby in couchDB.
> >>
> >>
> >> I'm trying to develop a "Google Analytics" like applications storing
> access log
> >> metadata in a CouchDB database. Take a look at
> >> http://github.com/fabiobatalha/Analytics---CouchDB/tree/master/logger/
> >>
> >> The idea is:
> >>
> >> Create a logger JavaScript that will be responsible to register all
> accesslog
> >> metadata in a CouchDB database. It works like the ga.js Google Anaytics.
> In the
> >> bottom of each page will hava a call to a JavaScript function that will
> make use
> >> of couch.js functions to register logaccess metadata in CouchDB
> >>
> >> The problem:
> >>
> >> I'm trying to make use of the couch.js script but the couch.js on works
> if the
> >> request is made from the same host and port were the CouchDB is
> installed.
> >> Instead of it, my application is in a different host. How can I
> configure the
> >> connection to the couchDB using the couch.js
> >>
> >>
> >> Thanks in advance.
> >> Fabio Batalha
> >>
> >>
> >>
> >>
>
>
Re: JavaScript and CouchDB
Posted by Tracy Flynn <co...@thisonejustforme.com>.
Fabio
You might consider the work-around offered by jQuery 1.4.x to the same-origin problem.
In a nutshell, they package all Ajax-like requests as a request for a resource - think image or javascript file - which does NOT have the limitations of the same-origin policy - and then 'unpack' the result and make it available to the client as if the 'Ajax-like' request had been issued directly.
A fragment like the following does the trick
<html>
<head>
<title>JSON Call Test Page</title>
<script type="text/javascript" src="http://localhost:8080/javascripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://localhost:8080/javascripts/json2.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$.getJSON("http://localhost:8080/some.js" ,
function(json){
$("#somelement").html(json.some_variable_containing_html);
$("#somelement").show();
}
)
});
</script>
</body>
</html>
The call that services the 'some.js' request just needs to return whatever JSON data you want the call to return. Since it's requesting a resource, and not really making an Ajax call - all is well.
If HTML isn't what you want, you could pass back Javascript embedded in a JSON structure, and then evaluate the result. I've done that successfully too.
Works like a charm where I've used the facility.
Tracy
On Oct 15, 2010, at 2:41 PM, Paul Davis wrote:
> You'll need to read up on the Same Origin Policy:
>
> http://en.wikipedia.org/wiki/Same_origin_policy
>
>
> On Fri, Oct 15, 2010 at 2:34 PM, Fabio Batalha C Santos Santos
> <fa...@yahoo.com.br> wrote:
>> Hello everybody,
>>
>> I'm newby in couchDB.
>>
>>
>> I'm trying to develop a "Google Analytics" like applications storing access log
>> metadata in a CouchDB database. Take a look at
>> http://github.com/fabiobatalha/Analytics---CouchDB/tree/master/logger/
>>
>> The idea is:
>>
>> Create a logger JavaScript that will be responsible to register all accesslog
>> metadata in a CouchDB database. It works like the ga.js Google Anaytics. In the
>> bottom of each page will hava a call to a JavaScript function that will make use
>> of couch.js functions to register logaccess metadata in CouchDB
>>
>> The problem:
>>
>> I'm trying to make use of the couch.js script but the couch.js on works if the
>> request is made from the same host and port were the CouchDB is installed.
>> Instead of it, my application is in a different host. How can I configure the
>> connection to the couchDB using the couch.js
>>
>>
>> Thanks in advance.
>> Fabio Batalha
>>
>>
>>
>>
Re: JavaScript and CouchDB
Posted by Paul Davis <pa...@gmail.com>.
You'll need to read up on the Same Origin Policy:
http://en.wikipedia.org/wiki/Same_origin_policy
On Fri, Oct 15, 2010 at 2:34 PM, Fabio Batalha C Santos Santos
<fa...@yahoo.com.br> wrote:
> Hello everybody,
>
> I'm newby in couchDB.
>
>
> I'm trying to develop a "Google Analytics" like applications storing access log
> metadata in a CouchDB database. Take a look at
> http://github.com/fabiobatalha/Analytics---CouchDB/tree/master/logger/
>
> The idea is:
>
> Create a logger JavaScript that will be responsible to register all accesslog
> metadata in a CouchDB database. It works like the ga.js Google Anaytics. In the
> bottom of each page will hava a call to a JavaScript function that will make use
> of couch.js functions to register logaccess metadata in CouchDB
>
> The problem:
>
> I'm trying to make use of the couch.js script but the couch.js on works if the
> request is made from the same host and port were the CouchDB is installed.
> Instead of it, my application is in a different host. How can I configure the
> connection to the couchDB using the couch.js
>
>
> Thanks in advance.
> Fabio Batalha
>
>
>
>
JavaScript and CouchDB
Posted by Fabio Batalha C Santos Santos <fa...@yahoo.com.br>.
Hello everybody,
I'm newby in couchDB.
I'm trying to develop a "Google Analytics" like applications storing access log
metadata in a CouchDB database. Take a look at
http://github.com/fabiobatalha/Analytics---CouchDB/tree/master/logger/
The idea is:
Create a logger JavaScript that will be responsible to register all accesslog
metadata in a CouchDB database. It works like the ga.js Google Anaytics. In the
bottom of each page will hava a call to a JavaScript function that will make use
of couch.js functions to register logaccess metadata in CouchDB
The problem:
I'm trying to make use of the couch.js script but the couch.js on works if the
request is made from the same host and port were the CouchDB is installed.
Instead of it, my application is in a different host. How can I configure the
connection to the couchDB using the couch.js
Thanks in advance.
Fabio Batalha
Re: Cooking Views
Posted by Robert Newson <ro...@gmail.com>.
Boolean queries can be achieved with a different index, fed from a
couchdb database.
For example: http://github.com/rnewson/couchdb-lucene
B.
On Fri, Oct 15, 2010 at 5:29 PM, Terry Brownell <te...@gmail.com> wrote:
> Thank Mark,
>
> My initial hunch was CouchDB isn't particularly suited as a triple store or
> running sparql type of queries .. too bad.. i was really digging the whole 2
> tier / replication thing.
>
> Terry
>
> On Fri, Oct 15, 2010 at 6:34 AM, Mark J. Reed <ma...@gmail.com> wrote:
>
>> On Thu, Oct 14, 2010 at 7:00 PM, Terry Brownell
>> <te...@trinitypower.com> wrote:
>> > Hi, attempting to port my semantic network DB to CouchDB, but I'm not
>> > grokking the more complicated views, and in particular passing variables.
>>
>> Depending on the types of query you anticipate, Couch (at least
>> without Solr) might not be the best choice for this problem domain.
>> In my experience it works best with canned queries that don't vary
>> much; if you have a bunch of ad-hoc queries with different types of
>> logic being composed on the fly, you may want to look at either adding
>> Solr to the mix or switching to another storage technology like
>> MongoDB.
>>
>> Having said that, here's how I would solve your specific problem in bare
>> Couch.
>>
>> > Looking for a cookbook recipe for creating a view (against the documents
>> > below), that...
>> >
>> > - Selects all documents where "isa" = "bird", that has a nemesis, and
>> color
>> > is a variable ie: all yellow?
>>
>> Create a view with a map function that emits the variable part as the
>> key, but only for documents matching the non-variable criteria. For
>> example,
>>
>> "map": "function(doc) { if (doc.nemesis && doc.isa == 'bird') {
>> emit(doc.color, doc.nemesis) }}"
>>
>> Then query that view with ?key="yellow".
>>
>> You can make it more flexible by emitting a complex key consisting of
>> [doc.isa, doc.color], instead of making it conditional on isa; then
>> you would query for key=["bird","yellow"]. What that gains you is the
>> ability not only to query for different combinations of animal and
>> color, but also to use a range query to look for specific animal types
>> regardless of color (e.g. startkey=["bird"]&endkey=["bird",{}] to get
>> all the nemesis-having birds). But order matters; with isa first, this
>> view doesn't help you if you want to query for all yellow
>> nemesis-having animals whether they're a bird or not. You would have
>> to construct a different view for that.
>>
>> --
>> Mark J. Reed <ma...@gmail.com>
>>
>
Re: Cooking Views
Posted by Terry Brownell <te...@gmail.com>.
Thank Mark,
My initial hunch was CouchDB isn't particularly suited as a triple store or
running sparql type of queries .. too bad.. i was really digging the whole 2
tier / replication thing.
Terry
On Fri, Oct 15, 2010 at 6:34 AM, Mark J. Reed <ma...@gmail.com> wrote:
> On Thu, Oct 14, 2010 at 7:00 PM, Terry Brownell
> <te...@trinitypower.com> wrote:
> > Hi, attempting to port my semantic network DB to CouchDB, but I'm not
> > grokking the more complicated views, and in particular passing variables.
>
> Depending on the types of query you anticipate, Couch (at least
> without Solr) might not be the best choice for this problem domain.
> In my experience it works best with canned queries that don't vary
> much; if you have a bunch of ad-hoc queries with different types of
> logic being composed on the fly, you may want to look at either adding
> Solr to the mix or switching to another storage technology like
> MongoDB.
>
> Having said that, here's how I would solve your specific problem in bare
> Couch.
>
> > Looking for a cookbook recipe for creating a view (against the documents
> > below), that...
> >
> > - Selects all documents where "isa" = "bird", that has a nemesis, and
> color
> > is a variable ie: all yellow?
>
> Create a view with a map function that emits the variable part as the
> key, but only for documents matching the non-variable criteria. For
> example,
>
> "map": "function(doc) { if (doc.nemesis && doc.isa == 'bird') {
> emit(doc.color, doc.nemesis) }}"
>
> Then query that view with ?key="yellow".
>
> You can make it more flexible by emitting a complex key consisting of
> [doc.isa, doc.color], instead of making it conditional on isa; then
> you would query for key=["bird","yellow"]. What that gains you is the
> ability not only to query for different combinations of animal and
> color, but also to use a range query to look for specific animal types
> regardless of color (e.g. startkey=["bird"]&endkey=["bird",{}] to get
> all the nemesis-having birds). But order matters; with isa first, this
> view doesn't help you if you want to query for all yellow
> nemesis-having animals whether they're a bird or not. You would have
> to construct a different view for that.
>
> --
> Mark J. Reed <ma...@gmail.com>
>
Re: Cooking Views
Posted by "Mark J. Reed" <ma...@gmail.com>.
On Thu, Oct 14, 2010 at 7:00 PM, Terry Brownell
<te...@trinitypower.com> wrote:
> Hi, attempting to port my semantic network DB to CouchDB, but I'm not
> grokking the more complicated views, and in particular passing variables.
Depending on the types of query you anticipate, Couch (at least
without Solr) might not be the best choice for this problem domain.
In my experience it works best with canned queries that don't vary
much; if you have a bunch of ad-hoc queries with different types of
logic being composed on the fly, you may want to look at either adding
Solr to the mix or switching to another storage technology like
MongoDB.
Having said that, here's how I would solve your specific problem in bare Couch.
> Looking for a cookbook recipe for creating a view (against the documents
> below), that...
>
> - Selects all documents where "isa" = "bird", that has a nemesis, and color
> is a variable ie: all yellow?
Create a view with a map function that emits the variable part as the
key, but only for documents matching the non-variable criteria. For
example,
"map": "function(doc) { if (doc.nemesis && doc.isa == 'bird') {
emit(doc.color, doc.nemesis) }}"
Then query that view with ?key="yellow".
You can make it more flexible by emitting a complex key consisting of
[doc.isa, doc.color], instead of making it conditional on isa; then
you would query for key=["bird","yellow"]. What that gains you is the
ability not only to query for different combinations of animal and
color, but also to use a range query to look for specific animal types
regardless of color (e.g. startkey=["bird"]&endkey=["bird",{}] to get
all the nemesis-having birds). But order matters; with isa first, this
view doesn't help you if you want to query for all yellow
nemesis-having animals whether they're a bird or not. You would have
to construct a different view for that.
--
Mark J. Reed <ma...@gmail.com>