Fetch multiple records from array of _ids

44 views
Skip to first unread message

Ami Kapadia

unread,
Aug 26, 2014, 1:07:25 PM8/26/14
to mobile-c...@googlegroups.com
Hi!

I am using PhoneGap CBLite.
I have created views which is returning null, so I get only _id of each records.
Now is there any way so that I can fetch multiple records from array of _ids? I have tried following code but seems not working.
    • var array1 = ["1","2"];
    • config.db.get(array1, function(err, doc){...})

Jens Alfke

unread,
Aug 26, 2014, 1:26:41 PM8/26/14
to mobile-c...@googlegroups.com

> On Aug 26, 2014, at 10:07 AM, Ami Kapadia <ami....@gmail.com> wrote:
>
> Now is there any way so that I can fetch multiple records from array of _ids? I have tried following code but seems not working.
> • var array1 = ["1","2"];
> • config.db.get(array1, function(err, doc){…})

What JS library are you using? Have you consulted its documentation? What unexpected results do you get from the call above?

BTW if you add the ?include_docs=true URL param when querying a view, you'll get the document bodies inline along with the rows.

—Jens

Ami Kapadia

unread,
Aug 26, 2014, 3:00:22 PM8/26/14
to mobile-c...@googlegroups.com
Hi Jens!

Thanks for your response.
See Inline

What JS library are you using? Have you consulted its documentation? What unexpected results do you get from the call above?

BTW if you add the ?include_docs=true URL param when querying a view, you'll get the document bodies inline along with the rows.
I don't get what are you talking about.
I am querying view like this :
config.views(["getrecords_typewise", {
startkey : "contact",
endkey : "contact",
descending : true
}], function(err, view)
{
//??
});

Thanks!



--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/D521492D-09CC-4D9F-B7C8-30DE7DDED83B%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Jens Alfke

unread,
Aug 26, 2014, 5:34:24 PM8/26/14
to mobile-c...@googlegroups.com

> On Aug 26, 2014, at 12:00 PM, Ami Kapadia <ami....@gmail.com> wrote:
>
> What JS library are you using? Have you consulted its documentation? What unexpected results do you get from the call above?
> I am using coax library which is used here : https://github.com/couchbaselabs/TodoLite-PhoneGap/blob/master/js/index.js

I looked around but couldn't find any documentation on coax. You might consider switching to a different CouchDB-compatible JS library with more support.

> BTW if you add the ?include_docs=true URL param when querying a view, you'll get the document bodies inline along with the rows.
> I don't get what are you talking about.
> I am querying view like this :
> config.views(["getrecords_typewise", {
> startkey : "contact",
> endkey : "contact",

Just insert:
include_docs: true,
there. The views() function takes the properties of that object you pass in and adds them to the URL as query parameters.

—Jens

Ami Kapadia

unread,
Aug 27, 2014, 4:29:07 PM8/27/14
to mobile-c...@googlegroups.com
I found it!

We can get multiple records using this : 
config.db.post(["_all_docs", {"include_docs":"true"}],{"keys" : ["_id1","_id2"]}, function(err,doc){ console.log(doc); })

Thanks!

Jens Alfke

unread,
Aug 27, 2014, 5:08:33 PM8/27/14
to mobile-c...@googlegroups.com
It would still be more efficient (and probably easier for you) to add the include_docs parameter during the first query.

—Jens

Ami Kapadia

unread,
Aug 28, 2014, 4:27:00 PM8/28/14
to mobile-c...@googlegroups.com
Thanks for suggestion. It worked. :)
Reply all
Reply to author
Forward
0 new messages