Multiple queries against a view

3 views
Skip to first unread message

Paul Milner

unread,
Sep 3, 2022, 5:29:28 AM9/3/22
to us...@couchdb.apache.org
Hello

I'm looking to execute a view multiple times at once for different keys
with different limits and skips (associated to each query). So I need the
following:

POST /recipes/_design/recipes/_view/by_title/queries
HTTP/1.1Content-Type: application/jsonAccept: application/jsonHost:
localhost:5984
{ "queries": [ { "keys": [
"meatballs", "spaghetti" ] },
{ "limit": 3, "skip": 2 } ]}

And I get the results object for each query. But can someone tell me
how I form the queries object for multiple queries please? Something
like:

{ "queries": [

{ "keys": [ "meatballs",
"spaghetti" ] }, { "limit": 3,
"skip": 2 },

{ "keys": [ "meatballs3",
"spaghetti3" ] }, { "limit":
4, "skip": 5 }

] }

or should this be done a different way? I'm only doing one key per
view. So it's a way to execute a query multiple times in bulk with
different limits and skips and get the array of results for each key.
I'm looking to do the following:

1) Get the count of each key and use this to get a random item within
the duplicates of the key.

2) Delete a random item with the duplicates of the key.

I see it as a way to prevent concurrence when deleting items with
multiple concurrent jobs.

I hope that's clear.

Thanks a lot

Best regards

Paul

Rene Veerman

unread,
Sep 30, 2022, 7:27:23 PM9/30/22
to us...@couchdb.apache.org
multi-threaded curl would seem the answer to this.
the view definition itself would enable a binary tree for the searches to
happen quickly, wouldn't it? <asking everyone here>

Rene Veerman

unread,
Sep 30, 2022, 7:31:27 PM9/30/22
to us...@couchdb.apache.org
https://github.com/NicerEnterprises/nicerapp/blob/main/NicerAppWebOS/apps/NicerAppWebOS/applications/2D/news/class.newsApp-3.php#L498
has an example of multi-threaded curl in PHP, in this case to request 400+
RSS servers for their latest results, but you could easily run a couple of
view queries with this as well.

Rene Veerman

unread,
Sep 30, 2022, 7:31:41 PM9/30/22
to us...@couchdb.apache.org
alternately, you could use your own current db-access business logic
routines, and request each view result through javascript, then combine the
data in javascript.

On Sat, Oct 1, 2022 at 1:28 AM Rene Veerman <

Rene Veerman

unread,
Sep 30, 2022, 7:37:35 PM9/30/22
to us...@couchdb.apache.org
>I see it as a way to prevent concurrence when deleting items with
multiple concurrent jobs.

what's the initiator of this job? coz i can't figure out what the
solution might really be here.

On Sat, Oct 1, 2022 at 1:30 AM Rene Veerman <

Paul Milner

unread,
Oct 1, 2022, 8:57:22 AM10/1/22
to us...@couchdb.apache.org
Hi Rene

Thanks for the answer. It was my misunderstanding of how to use the
multiple queries for the same view. It wasn't really clear to me from the
documentation that you do the following:


var bulkQuery = {
"queries": []
}

let query = {
"key": "some key",
"skip": howeverymany,
"limit": whatever
}

And then post bulkquery with multiple varying queries to the queries
endpoint.

But I figured it out eventually.

But thanks for replying anyway.

Paul
Reply all
Reply to author
Forward
0 new messages