You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Mic <mi...@gmail.com> on 2015/01/02 02:01:47 UTC
Retrieving selected documents in CouchDB
Hi,
I have the following example document in CouchDB stored:
*{
"_id": "10",
"_rev": "3-5288068d2c4ef3e6a9d3f8ff4e3377dd",
"sub_name": "B01",
"name": "A",
"pos": 1932523,
"s_type": 1,
}*
The map function looks in the following way:
*function(doc) {
emit(doc._id, {position: doc.pos});
}*
and the view returns the following results.
*http://localhost:5984/test/_design/t/_view/by_doc_ids
<http://localhost:5984/test/_design/t/_view/by_doc_ids>*
*{"total_rows":5,"offset":0,"rows":[
{"id":"10","key":"10","value":{"position":1932523}},
{"id":"14","key":"14","value":{"position":667214}},
{"id":"7","key":"7","value":{"position":828288}},
{"id":"8","key":"8","value":{"position":171878}},
{"id":"9","key":"9","value":{"position":871963}}
]}*
However, *http://localhost:5984/test/_design/t/_view/by_doc_ids
<http://localhost:5984/test/_design/t/_view/by_doc_ids>?id=[7,10]*
returns all of them.
{"total_rows":5,"offset":0,"rows":[
{"id":"10","key":"10","value":{"position":1932523}},
{"id":"14","key":"14","value":{"position":667214}},
{"id":"7","key":"7","value":{"position":828288}},
{"id":"8","key":"8","value":{"position":171878}},
{"id":"9","key":"9","value":{"position":871963}}
]}
and *http://localhost:5984/test/_design/t/_view/by_doc_ids
<http://localhost:5984/test/_design/t/_view/by_doc_ids>?keys=[7,10]
*returns nothing:
*{"total_rows":5,"offset":0,"rows":[
]}*
How do I get only ids with 7 and 10?
*{"id":"7","key":"7","value":{"position":828288}}*
*{"id":"10","key":"10","value":{"position":1932523}}*
Thank you in advance.
Mic
Re: Retrieving selected documents in CouchDB
Posted by Mic <mi...@gmail.com>.
Thank you.
On Fri, Jan 2, 2015 at 12:24 PM, Alexander Shorin <kx...@gmail.com> wrote:
> Also to retrieve multiple documents by their id you don't need in
> special view. Built-in /db/_all_docs serves perfect for this case.
> --
> ,,,^..^,,,
>
>
> On Fri, Jan 2, 2015 at 5:14 AM, Mic <mi...@gmail.com> wrote:
> > Thank you it works.
> >
> > On Fri, Jan 2, 2015 at 11:40 AM, Giovanni P <fi...@gmail.com> wrote:
> >
> >> if your ids are strings your query parameter should be ?keys=["7", "10"]
> >>
> >> On Thu, Jan 1, 2015 at 11:01 PM, Mic <mi...@gmail.com> wrote:
> >>
> >> > Hi,
> >> >
> >> > I have the following example document in CouchDB stored:
> >> >
> >> > *{
> >> > "_id": "10",
> >> > "_rev": "3-5288068d2c4ef3e6a9d3f8ff4e3377dd",
> >> > "sub_name": "B01",
> >> > "name": "A",
> >> > "pos": 1932523,
> >> > "s_type": 1,
> >> > }*
> >> >
> >> > The map function looks in the following way:
> >> >
> >> > *function(doc) {
> >> > emit(doc._id, {position: doc.pos});
> >> > }*
> >> >
> >> > and the view returns the following results.
> >> >
> >> >
> >> > *http://localhost:5984/test/_design/t/_view/by_doc_ids
> >> > <http://localhost:5984/test/_design/t/_view/by_doc_ids>*
> >> >
> >> > *{"total_rows":5,"offset":0,"rows":[
> >> > {"id":"10","key":"10","value":{"position":1932523}},
> >> > {"id":"14","key":"14","value":{"position":667214}},
> >> > {"id":"7","key":"7","value":{"position":828288}},
> >> > {"id":"8","key":"8","value":{"position":171878}},
> >> > {"id":"9","key":"9","value":{"position":871963}}
> >> > ]}*
> >> >
> >> > However, *http://localhost:5984/test/_design/t/_view/by_doc_ids
> >> > <http://localhost:5984/test/_design/t/_view/by_doc_ids>?id=[7,10]*
> >> > returns all of them.
> >> >
> >> > {"total_rows":5,"offset":0,"rows":[
> >> > {"id":"10","key":"10","value":{"position":1932523}},
> >> > {"id":"14","key":"14","value":{"position":667214}},
> >> > {"id":"7","key":"7","value":{"position":828288}},
> >> > {"id":"8","key":"8","value":{"position":171878}},
> >> > {"id":"9","key":"9","value":{"position":871963}}
> >> > ]}
> >> >
> >> > and *http://localhost:5984/test/_design/t/_view/by_doc_ids
> >> > <http://localhost:5984/test/_design/t/_view/by_doc_ids>?keys=[7,10]
> >> > *returns nothing:
> >> >
> >> > *{"total_rows":5,"offset":0,"rows":[
> >> >
> >> > ]}*
> >> >
> >> > How do I get only ids with 7 and 10?
> >> >
> >> > *{"id":"7","key":"7","value":{"position":828288}}*
> >> >
> >> > *{"id":"10","key":"10","value":{"position":1932523}}*
> >> >
> >> > Thank you in advance.
> >> >
> >> > Mic
> >> >
> >>
>
Re: Retrieving selected documents in CouchDB
Posted by Alexander Shorin <kx...@gmail.com>.
Also to retrieve multiple documents by their id you don't need in
special view. Built-in /db/_all_docs serves perfect for this case.
--
,,,^..^,,,
On Fri, Jan 2, 2015 at 5:14 AM, Mic <mi...@gmail.com> wrote:
> Thank you it works.
>
> On Fri, Jan 2, 2015 at 11:40 AM, Giovanni P <fi...@gmail.com> wrote:
>
>> if your ids are strings your query parameter should be ?keys=["7", "10"]
>>
>> On Thu, Jan 1, 2015 at 11:01 PM, Mic <mi...@gmail.com> wrote:
>>
>> > Hi,
>> >
>> > I have the following example document in CouchDB stored:
>> >
>> > *{
>> > "_id": "10",
>> > "_rev": "3-5288068d2c4ef3e6a9d3f8ff4e3377dd",
>> > "sub_name": "B01",
>> > "name": "A",
>> > "pos": 1932523,
>> > "s_type": 1,
>> > }*
>> >
>> > The map function looks in the following way:
>> >
>> > *function(doc) {
>> > emit(doc._id, {position: doc.pos});
>> > }*
>> >
>> > and the view returns the following results.
>> >
>> >
>> > *http://localhost:5984/test/_design/t/_view/by_doc_ids
>> > <http://localhost:5984/test/_design/t/_view/by_doc_ids>*
>> >
>> > *{"total_rows":5,"offset":0,"rows":[
>> > {"id":"10","key":"10","value":{"position":1932523}},
>> > {"id":"14","key":"14","value":{"position":667214}},
>> > {"id":"7","key":"7","value":{"position":828288}},
>> > {"id":"8","key":"8","value":{"position":171878}},
>> > {"id":"9","key":"9","value":{"position":871963}}
>> > ]}*
>> >
>> > However, *http://localhost:5984/test/_design/t/_view/by_doc_ids
>> > <http://localhost:5984/test/_design/t/_view/by_doc_ids>?id=[7,10]*
>> > returns all of them.
>> >
>> > {"total_rows":5,"offset":0,"rows":[
>> > {"id":"10","key":"10","value":{"position":1932523}},
>> > {"id":"14","key":"14","value":{"position":667214}},
>> > {"id":"7","key":"7","value":{"position":828288}},
>> > {"id":"8","key":"8","value":{"position":171878}},
>> > {"id":"9","key":"9","value":{"position":871963}}
>> > ]}
>> >
>> > and *http://localhost:5984/test/_design/t/_view/by_doc_ids
>> > <http://localhost:5984/test/_design/t/_view/by_doc_ids>?keys=[7,10]
>> > *returns nothing:
>> >
>> > *{"total_rows":5,"offset":0,"rows":[
>> >
>> > ]}*
>> >
>> > How do I get only ids with 7 and 10?
>> >
>> > *{"id":"7","key":"7","value":{"position":828288}}*
>> >
>> > *{"id":"10","key":"10","value":{"position":1932523}}*
>> >
>> > Thank you in advance.
>> >
>> > Mic
>> >
>>
Re: Retrieving selected documents in CouchDB
Posted by Mic <mi...@gmail.com>.
Thank you it works.
On Fri, Jan 2, 2015 at 11:40 AM, Giovanni P <fi...@gmail.com> wrote:
> if your ids are strings your query parameter should be ?keys=["7", "10"]
>
> On Thu, Jan 1, 2015 at 11:01 PM, Mic <mi...@gmail.com> wrote:
>
> > Hi,
> >
> > I have the following example document in CouchDB stored:
> >
> > *{
> > "_id": "10",
> > "_rev": "3-5288068d2c4ef3e6a9d3f8ff4e3377dd",
> > "sub_name": "B01",
> > "name": "A",
> > "pos": 1932523,
> > "s_type": 1,
> > }*
> >
> > The map function looks in the following way:
> >
> > *function(doc) {
> > emit(doc._id, {position: doc.pos});
> > }*
> >
> > and the view returns the following results.
> >
> >
> > *http://localhost:5984/test/_design/t/_view/by_doc_ids
> > <http://localhost:5984/test/_design/t/_view/by_doc_ids>*
> >
> > *{"total_rows":5,"offset":0,"rows":[
> > {"id":"10","key":"10","value":{"position":1932523}},
> > {"id":"14","key":"14","value":{"position":667214}},
> > {"id":"7","key":"7","value":{"position":828288}},
> > {"id":"8","key":"8","value":{"position":171878}},
> > {"id":"9","key":"9","value":{"position":871963}}
> > ]}*
> >
> > However, *http://localhost:5984/test/_design/t/_view/by_doc_ids
> > <http://localhost:5984/test/_design/t/_view/by_doc_ids>?id=[7,10]*
> > returns all of them.
> >
> > {"total_rows":5,"offset":0,"rows":[
> > {"id":"10","key":"10","value":{"position":1932523}},
> > {"id":"14","key":"14","value":{"position":667214}},
> > {"id":"7","key":"7","value":{"position":828288}},
> > {"id":"8","key":"8","value":{"position":171878}},
> > {"id":"9","key":"9","value":{"position":871963}}
> > ]}
> >
> > and *http://localhost:5984/test/_design/t/_view/by_doc_ids
> > <http://localhost:5984/test/_design/t/_view/by_doc_ids>?keys=[7,10]
> > *returns nothing:
> >
> > *{"total_rows":5,"offset":0,"rows":[
> >
> > ]}*
> >
> > How do I get only ids with 7 and 10?
> >
> > *{"id":"7","key":"7","value":{"position":828288}}*
> >
> > *{"id":"10","key":"10","value":{"position":1932523}}*
> >
> > Thank you in advance.
> >
> > Mic
> >
>
Re: Retrieving selected documents in CouchDB
Posted by Giovanni P <fi...@gmail.com>.
if your ids are strings your query parameter should be ?keys=["7", "10"]
On Thu, Jan 1, 2015 at 11:01 PM, Mic <mi...@gmail.com> wrote:
> Hi,
>
> I have the following example document in CouchDB stored:
>
> *{
> "_id": "10",
> "_rev": "3-5288068d2c4ef3e6a9d3f8ff4e3377dd",
> "sub_name": "B01",
> "name": "A",
> "pos": 1932523,
> "s_type": 1,
> }*
>
> The map function looks in the following way:
>
> *function(doc) {
> emit(doc._id, {position: doc.pos});
> }*
>
> and the view returns the following results.
>
>
> *http://localhost:5984/test/_design/t/_view/by_doc_ids
> <http://localhost:5984/test/_design/t/_view/by_doc_ids>*
>
> *{"total_rows":5,"offset":0,"rows":[
> {"id":"10","key":"10","value":{"position":1932523}},
> {"id":"14","key":"14","value":{"position":667214}},
> {"id":"7","key":"7","value":{"position":828288}},
> {"id":"8","key":"8","value":{"position":171878}},
> {"id":"9","key":"9","value":{"position":871963}}
> ]}*
>
> However, *http://localhost:5984/test/_design/t/_view/by_doc_ids
> <http://localhost:5984/test/_design/t/_view/by_doc_ids>?id=[7,10]*
> returns all of them.
>
> {"total_rows":5,"offset":0,"rows":[
> {"id":"10","key":"10","value":{"position":1932523}},
> {"id":"14","key":"14","value":{"position":667214}},
> {"id":"7","key":"7","value":{"position":828288}},
> {"id":"8","key":"8","value":{"position":171878}},
> {"id":"9","key":"9","value":{"position":871963}}
> ]}
>
> and *http://localhost:5984/test/_design/t/_view/by_doc_ids
> <http://localhost:5984/test/_design/t/_view/by_doc_ids>?keys=[7,10]
> *returns nothing:
>
> *{"total_rows":5,"offset":0,"rows":[
>
> ]}*
>
> How do I get only ids with 7 and 10?
>
> *{"id":"7","key":"7","value":{"position":828288}}*
>
> *{"id":"10","key":"10","value":{"position":1932523}}*
>
> Thank you in advance.
>
> Mic
>