You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Alexander Gabriel <al...@barbalex.ch> on 2011/05/15 22:34:12 UTC

fetching data: how to filter?

Hi
I want to fetch documents from a CouchDb named evab. The documents include a
field "Typ" and I want to fetch those with Typ = Beobachtung.

So far I've tried:

   - curl -d "{\"Typ\":\"Beobachtung\"}" -X POST
   http://username:secretpassword@127.0.0.1:5984/evab/_bulk_docs?include_docs=true>
Beobachtungen.json
   - curl -d "{\"docs\": [{\"Typ\":\"Beobachtung\"}]}" -X POST
   http://username:secretpassword@127.0.0.1:5984/evab/_all_docs?include_docs=true>
Beobachtungen.json
   - replacing {\"Typ\":\"Beobachtung\"} or {\"docs\":
   [{\"Typ\":\"Beobachtung\"}]} with "@TypBeob_Kriterien.json" to circumvent
   problems with the windows-command-tool and " or '.

I consistently get all the data of all the docs in the CouchDb.

>From the documentation I have not understood:

   - _all_docs or _bulk_docs? It seems that both work the same.
   - Is ist maybe only possible to filter with keys = _id's?
   - Is it possible to fetch the data from a view?


Or simply: What is the best way to do it?

Thanks for help!

Alexander Gabriel

Re: fetching data: how to filter?

Posted by Alexander Gabriel <al...@barbalex.ch>.
Thanks Gabor!

Alexander Gabriel
Am 16.05.2011 09:37 schrieb "Gabor Ratky" <rg...@rgabostyle.com>:
> Alex,
>
> as with everyone new to CouchDB (and/or NoSQL) I recommend going through
the CouchDB: Definitive Guide [1]. It is an indispensable resource and gives
you a great overview of CouchDB. It makes it much easier to understand the
concepts and the design behind CouchDB. Afterwards, you can just refer to
the CouchDB Wiki [2] or the HTTP API Reference in the new Techzone by
Couchbase [3].
>
> Have fun with Couch!
>
> Gabor
>
> [1] http://guide.couchdb.org/
> [2] http://wiki.apache.org/couchdb/
> [3]
http://techzone.couchbase.com/sites/default/files/uploads/all/documentation/couchbase-api.html
> On Monday, May 16, 2011 at 12:29 AM, Alexander Gabriel wrote:
> That is very helpful and answers my questions.
>> Thanks for taking so much time. Your effort is very much appreciated!
>>
>> Alexander Gabriel
>>
>>
>>
>>
>> 2011/5/16 Jim Klo <ji...@sri.com>
>>
>> >
>> > To understand views:
>> > http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
>> >
>> > A map function might look like:
>> >
>> > function (doc) {
>> >
>> > if (doc.Typ) {
>> > emit(doc.Typ, null);
>> > }
>> >
>> > }
>> >
>> >
>> > then to query the view:
>> >
>> > curl -X GET "
>> >
http://localhost:5981/dbname/_design/docname/_view/viewname?key=%22Beobachtung%22&include_docs=true
>> >
>> > See http://wiki.apache.org/couchdb/HTTP_view_API for details on
querying
>> > views and other options.
>> >
>> >
>> >
>> > *
>> > Jim Klo
>> > Senior Software Engineer
>> > Center for Software Engineering
>> > SRI International
>> > *
>> >
>> >
>> >
>> >
>> > On May 15, 2011, at 2:18 PM, Alexander Gabriel wrote:
>> >
>> > thanks a lot for your help. So I can define a view that includes the
Typ
>> > field and filter for it.
>> > But how do I fetch the data from the view using curl?
>> >
>> > Using a list seems like more work.
>> >
>> > Alexander Gabriel
>> >
>> >
>> >
>> >
>> > 2011/5/15 Jim Klo <ji...@sri.com>
>> >
>> > You need to define a view, using the name as at least part of the key
or
>> >
>> > create a list. Then you can filter using the key in a view or some
>> > parameter
>> >
>> > you pass using a list.
>> >
>> >
>> > I suggest taking a look a Max Ogden's talk on CouchDB. It's a great
>> >
>> > jumpstart for a newbie.
>> >
>> >
>> > http://vimeo.com/18808177
>> >
>> >
>> > - Jim
>> >
>> >
>> >
>> > On May 15, 2011, at 1:34 PM, Alexander Gabriel <al...@barbalex.ch>
wrote:
>> >
>> >
>> > Hi
>> >
>> > I want to fetch documents from a CouchDb named evab. The documents
>> >
>> > include a
>> >
>> > field "Typ" and I want to fetch those with Typ = Beobachtung.
>> >
>> >
>> > So far I've tried:
>> >
>> >
>> > - curl -d "{\"Typ\":\"Beobachtung\"}" -X POST
>> >
>> >
>> >
>> >
http://username:secretpassword@127.0.0.1:5984/evab/_bulk_docs?include_docs=true
>> >
>> >
>> > Beobachtungen.json
>> >
>> > - curl -d "{\"docs\": [{\"Typ\":\"Beobachtung\"}]}" -X POST
>> >
>> >
>> >
>> >
http://username:secretpassword@127.0.0.1:5984/evab/_all_docs?include_docs=true
>> >
>> >
>> > Beobachtungen.json
>> >
>> > - replacing {\"Typ\":\"Beobachtung\"} or {\"docs\":
>> >
>> > [{\"Typ\":\"Beobachtung\"}]} with "@TypBeob_Kriterien.json" to
>> >
>> > circumvent
>> >
>> > problems with the windows-command-tool and " or '.
>> >
>> >
>> > I consistently get all the data of all the docs in the CouchDb.
>> >
>> >
>> > From the documentation I have not understood:
>> >
>> >
>> > - _all_docs or _bulk_docs? It seems that both work the same.
>> >
>> > - Is ist maybe only possible to filter with keys = _id's?
>> >
>> > - Is it possible to fetch the data from a view?
>> >
>> >
>> >
>> > Or simply: What is the best way to do it?
>> >
>> >
>> > Thanks for help!
>> >
>> >
>> > Alexander Gabriel
>>

Re: fetching data: how to filter?

Posted by Gabor Ratky <rg...@rgabostyle.com>.
Alex,

as with everyone new to CouchDB (and/or NoSQL) I recommend going through the CouchDB: Definitive Guide [1]. It is an indispensable resource and gives you a great overview of CouchDB. It makes it much easier to understand the concepts and the design behind CouchDB. Afterwards, you can just refer to the CouchDB Wiki [2] or the HTTP API Reference in the new Techzone by Couchbase [3].

Have fun with Couch!

Gabor

[1] http://guide.couchdb.org/
[2] http://wiki.apache.org/couchdb/
[3] http://techzone.couchbase.com/sites/default/files/uploads/all/documentation/couchbase-api.html
On Monday, May 16, 2011 at 12:29 AM, Alexander Gabriel wrote:
That is very helpful and answers my questions.
> Thanks for taking so much time. Your effort is very much appreciated!
> 
> Alexander Gabriel
> 
> 
> 
> 
> 2011/5/16 Jim Klo <ji...@sri.com>
> 
> > 
> > To understand views:
> > http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
> > 
> > A map function might look like:
> > 
> > function (doc) {
> > 
> > if (doc.Typ) {
> > emit(doc.Typ, null);
> > }
> > 
> > }
> > 
> > 
> > then to query the view:
> > 
> > curl -X GET "
> > http://localhost:5981/dbname/_design/docname/_view/viewname?key=%22Beobachtung%22&include_docs=true
> > 
> > See http://wiki.apache.org/couchdb/HTTP_view_API for details on querying
> > views and other options.
> > 
> > 
> > 
> > *
> > Jim Klo
> > Senior Software Engineer
> > Center for Software Engineering
> > SRI International
> > *
> > 
> > 
> > 
> > 
> > On May 15, 2011, at 2:18 PM, Alexander Gabriel wrote:
> > 
> > thanks a lot for your help. So I can define a view that includes the Typ
> > field and filter for it.
> > But how do I fetch the data from the view using curl?
> > 
> > Using a list seems like more work.
> > 
> > Alexander Gabriel
> > 
> > 
> > 
> > 
> > 2011/5/15 Jim Klo <ji...@sri.com>
> > 
> > You need to define a view, using the name as at least part of the key or
> > 
> > create a list. Then you can filter using the key in a view or some
> > parameter
> > 
> > you pass using a list.
> > 
> > 
> > I suggest taking a look a Max Ogden's talk on CouchDB. It's a great
> > 
> > jumpstart for a newbie.
> > 
> > 
> > http://vimeo.com/18808177
> > 
> > 
> > - Jim
> > 
> > 
> > 
> > On May 15, 2011, at 1:34 PM, Alexander Gabriel <al...@barbalex.ch> wrote:
> > 
> > 
> > Hi
> > 
> > I want to fetch documents from a CouchDb named evab. The documents
> > 
> > include a
> > 
> > field "Typ" and I want to fetch those with Typ = Beobachtung.
> > 
> > 
> > So far I've tried:
> > 
> > 
> >  - curl -d "{\"Typ\":\"Beobachtung\"}" -X POST
> > 
> > 
> > 
> > http://username:secretpassword@127.0.0.1:5984/evab/_bulk_docs?include_docs=true
> > 
> > 
> > Beobachtungen.json
> > 
> >  - curl -d "{\"docs\": [{\"Typ\":\"Beobachtung\"}]}" -X POST
> > 
> > 
> > 
> > http://username:secretpassword@127.0.0.1:5984/evab/_all_docs?include_docs=true
> > 
> > 
> > Beobachtungen.json
> > 
> >  - replacing {\"Typ\":\"Beobachtung\"} or {\"docs\":
> > 
> >  [{\"Typ\":\"Beobachtung\"}]} with "@TypBeob_Kriterien.json" to
> > 
> > circumvent
> > 
> >  problems with the windows-command-tool and " or '.
> > 
> > 
> > I consistently get all the data of all the docs in the CouchDb.
> > 
> > 
> > From the documentation I have not understood:
> > 
> > 
> >  - _all_docs or _bulk_docs? It seems that both work the same.
> > 
> >  - Is ist maybe only possible to filter with keys = _id's?
> > 
> >  - Is it possible to fetch the data from a view?
> > 
> > 
> > 
> > Or simply: What is the best way to do it?
> > 
> > 
> > Thanks for help!
> > 
> > 
> > Alexander Gabriel
> 

Re: fetching data: how to filter?

Posted by Alexander Gabriel <al...@barbalex.ch>.
That is very helpful and answers my questions.
Thanks for taking so much time. Your effort is very much appreciated!

Alexander Gabriel




2011/5/16 Jim Klo <ji...@sri.com>

>
> To understand views:
> http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views
>
> A map function might look like:
>
> function (doc) {
>
> if (doc.Typ) {
> emit(doc.Typ, null);
> }
>
> }
>
>
> then to query the view:
>
> curl -X GET "
> http://localhost:5981/dbname/_design/docname/_view/viewname?key=%22Beobachtung%22&include_docs=true
>
> See http://wiki.apache.org/couchdb/HTTP_view_API for details on querying
> views and other options.
>
>
>
> *
> Jim Klo
> Senior Software Engineer
> Center for Software Engineering
> SRI International
> *
>
>
>
>
> On May 15, 2011, at 2:18 PM, Alexander Gabriel wrote:
>
> thanks a lot for your help. So I can define a view that includes the Typ
> field and filter for it.
> But how do I fetch the data from the view using curl?
>
> Using a list seems like more work.
>
> Alexander Gabriel
>
>
>
>
> 2011/5/15 Jim Klo <ji...@sri.com>
>
> You need to define a view, using the name as at least part of the key or
>
> create a list. Then you can filter using the key in a view or some
> parameter
>
> you pass using a list.
>
>
> I suggest taking a look a Max Ogden's talk on CouchDB. It's a great
>
> jumpstart for a newbie.
>
>
> http://vimeo.com/18808177
>
>
> - Jim
>
>
>
> On May 15, 2011, at 1:34 PM, Alexander Gabriel <al...@barbalex.ch> wrote:
>
>
> Hi
>
> I want to fetch documents from a CouchDb named evab. The documents
>
> include a
>
> field "Typ" and I want to fetch those with Typ = Beobachtung.
>
>
> So far I've tried:
>
>
>  - curl -d "{\"Typ\":\"Beobachtung\"}" -X POST
>
>
>
> http://username:secretpassword@127.0.0.1:5984/evab/_bulk_docs?include_docs=true
>
>
> Beobachtungen.json
>
>  - curl -d "{\"docs\": [{\"Typ\":\"Beobachtung\"}]}" -X POST
>
>
>
> http://username:secretpassword@127.0.0.1:5984/evab/_all_docs?include_docs=true
>
>
> Beobachtungen.json
>
>  - replacing {\"Typ\":\"Beobachtung\"} or {\"docs\":
>
>  [{\"Typ\":\"Beobachtung\"}]} with "@TypBeob_Kriterien.json" to
>
> circumvent
>
>  problems with the windows-command-tool and " or '.
>
>
> I consistently get all the data of all the docs in the CouchDb.
>
>
> From the documentation I have not understood:
>
>
>  - _all_docs or _bulk_docs? It seems that both work the same.
>
>  - Is ist maybe only possible to filter with keys = _id's?
>
>  - Is it possible to fetch the data from a view?
>
>
>
> Or simply: What is the best way to do it?
>
>
> Thanks for help!
>
>
> Alexander Gabriel
>
>
>
>

Re: fetching data: how to filter?

Posted by Jim Klo <ji...@sri.com>.
To understand views: http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views

A map function might look like:

function (doc) {

	if (doc.Typ) {
		emit(doc.Typ, null);
	}

}


then to query the view:

curl -X GET "http://localhost:5981/dbname/_design/docname/_view/viewname?key=%22Beobachtung%22&include_docs=true

See http://wiki.apache.org/couchdb/HTTP_view_API for details on querying views and other options.



Jim Klo
Senior Software Engineer
Center for Software Engineering
SRI International




On May 15, 2011, at 2:18 PM, Alexander Gabriel wrote:

> thanks a lot for your help. So I can define a view that includes the Typ
> field and filter for it.
> But how do I fetch the data from the view using curl?
> 
> Using a list seems like more work.
> 
> Alexander Gabriel
> 
> 
> 
> 
> 2011/5/15 Jim Klo <ji...@sri.com>
> 
>> You need to define a view, using the name as at least part of the key or
>> create a list. Then you can filter using the key in a view or some parameter
>> you pass using a list.
>> 
>> I suggest taking a look a Max Ogden's talk on CouchDB. It's a great
>> jumpstart for a newbie.
>> 
>> http://vimeo.com/18808177
>> 
>> - Jim
>> 
>> 
>> On May 15, 2011, at 1:34 PM, Alexander Gabriel <al...@barbalex.ch> wrote:
>> 
>>> Hi
>>> I want to fetch documents from a CouchDb named evab. The documents
>> include a
>>> field "Typ" and I want to fetch those with Typ = Beobachtung.
>>> 
>>> So far I've tried:
>>> 
>>>  - curl -d "{\"Typ\":\"Beobachtung\"}" -X POST
>>> 
>> http://username:secretpassword@127.0.0.1:5984/evab/_bulk_docs?include_docs=true
>>> 
>>> Beobachtungen.json
>>>  - curl -d "{\"docs\": [{\"Typ\":\"Beobachtung\"}]}" -X POST
>>> 
>> http://username:secretpassword@127.0.0.1:5984/evab/_all_docs?include_docs=true
>>> 
>>> Beobachtungen.json
>>>  - replacing {\"Typ\":\"Beobachtung\"} or {\"docs\":
>>>  [{\"Typ\":\"Beobachtung\"}]} with "@TypBeob_Kriterien.json" to
>> circumvent
>>>  problems with the windows-command-tool and " or '.
>>> 
>>> I consistently get all the data of all the docs in the CouchDb.
>>> 
>>> From the documentation I have not understood:
>>> 
>>>  - _all_docs or _bulk_docs? It seems that both work the same.
>>>  - Is ist maybe only possible to filter with keys = _id's?
>>>  - Is it possible to fetch the data from a view?
>>> 
>>> 
>>> Or simply: What is the best way to do it?
>>> 
>>> Thanks for help!
>>> 
>>> Alexander Gabriel
>> 


Re: fetching data: how to filter?

Posted by Alexander Gabriel <al...@barbalex.ch>.
thanks a lot for your help. So I can define a view that includes the Typ
field and filter for it.
But how do I fetch the data from the view using curl?

Using a list seems like more work.

 Alexander Gabriel




2011/5/15 Jim Klo <ji...@sri.com>

> You need to define a view, using the name as at least part of the key or
> create a list. Then you can filter using the key in a view or some parameter
> you pass using a list.
>
> I suggest taking a look a Max Ogden's talk on CouchDB. It's a great
> jumpstart for a newbie.
>
> http://vimeo.com/18808177
>
> - Jim
>
>
> On May 15, 2011, at 1:34 PM, Alexander Gabriel <al...@barbalex.ch> wrote:
>
> > Hi
> > I want to fetch documents from a CouchDb named evab. The documents
> include a
> > field "Typ" and I want to fetch those with Typ = Beobachtung.
> >
> > So far I've tried:
> >
> >   - curl -d "{\"Typ\":\"Beobachtung\"}" -X POST
> >
> http://username:secretpassword@127.0.0.1:5984/evab/_bulk_docs?include_docs=true
> >
> > Beobachtungen.json
> >   - curl -d "{\"docs\": [{\"Typ\":\"Beobachtung\"}]}" -X POST
> >
> http://username:secretpassword@127.0.0.1:5984/evab/_all_docs?include_docs=true
> >
> > Beobachtungen.json
> >   - replacing {\"Typ\":\"Beobachtung\"} or {\"docs\":
> >   [{\"Typ\":\"Beobachtung\"}]} with "@TypBeob_Kriterien.json" to
> circumvent
> >   problems with the windows-command-tool and " or '.
> >
> > I consistently get all the data of all the docs in the CouchDb.
> >
> > From the documentation I have not understood:
> >
> >   - _all_docs or _bulk_docs? It seems that both work the same.
> >   - Is ist maybe only possible to filter with keys = _id's?
> >   - Is it possible to fetch the data from a view?
> >
> >
> > Or simply: What is the best way to do it?
> >
> > Thanks for help!
> >
> > Alexander Gabriel
>

Re: fetching data: how to filter?

Posted by Jim Klo <ji...@sri.com>.
You need to define a view, using the name as at least part of the key or create a list. Then you can filter using the key in a view or some parameter you pass using a list. 

I suggest taking a look a Max Ogden's talk on CouchDB. It's a great jumpstart for a newbie. 

http://vimeo.com/18808177

- Jim


On May 15, 2011, at 1:34 PM, Alexander Gabriel <al...@barbalex.ch> wrote:

> Hi
> I want to fetch documents from a CouchDb named evab. The documents include a
> field "Typ" and I want to fetch those with Typ = Beobachtung.
> 
> So far I've tried:
> 
>   - curl -d "{\"Typ\":\"Beobachtung\"}" -X POST
>   http://username:secretpassword@127.0.0.1:5984/evab/_bulk_docs?include_docs=true>
> Beobachtungen.json
>   - curl -d "{\"docs\": [{\"Typ\":\"Beobachtung\"}]}" -X POST
>   http://username:secretpassword@127.0.0.1:5984/evab/_all_docs?include_docs=true>
> Beobachtungen.json
>   - replacing {\"Typ\":\"Beobachtung\"} or {\"docs\":
>   [{\"Typ\":\"Beobachtung\"}]} with "@TypBeob_Kriterien.json" to circumvent
>   problems with the windows-command-tool and " or '.
> 
> I consistently get all the data of all the docs in the CouchDb.
> 
> From the documentation I have not understood:
> 
>   - _all_docs or _bulk_docs? It seems that both work the same.
>   - Is ist maybe only possible to filter with keys = _id's?
>   - Is it possible to fetch the data from a view?
> 
> 
> Or simply: What is the best way to do it?
> 
> Thanks for help!
> 
> Alexander Gabriel