You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Stefan Klein <st...@gmail.com> on 2021/07/06 09:42:00 UTC

Equivalent of object.values() in mango?

Hi,

I'm trying to migrate an existing view to mango since this would allow for
some optimisations.
The documents contain a structure like:

"refs" : {
     "foo" : ["ABC","TFG"],
     "bar" : ["KOL","ABC"]
}
I need to find all documents where any of the arrays contain a given value,
regardless of the key (which is not known in this case).

With the existing operators it seams not to be possible to match on the
values of an object.
(A very big $or would technically possible, but that would be really ugly.)

Am I missing something?

regards,
Stefan

Re: Equivalent of object.values() in mango?

Posted by Balkrishna Agarwal <ag...@gmail.com>.
Hi Stefan!

You will have to use map functionality for this I believe. It might look something like this I believe.

let dataRequired = pouchDB.query((doc) => {
    if(refs.foo.includes(key) || refs.bar.includes(key)) {
        emit(doc._id);
    }
},
{
    include_docs: true
})

I hope this helps.

Krishna.

> On 06-Jul-2021, at 3:12 PM, Stefan Klein <st...@gmail.com> wrote:
> 
> Hi,
> 
> I'm trying to migrate an existing view to mango since this would allow for
> some optimisations.
> The documents contain a structure like:
> 
> "refs" : {
>     "foo" : ["ABC","TFG"],
>     "bar" : ["KOL","ABC"]
> }
> I need to find all documents where any of the arrays contain a given value,
> regardless of the key (which is not known in this case).
> 
> With the existing operators it seams not to be possible to match on the
> values of an object.
> (A very big $or would technically possible, but that would be really ugly.)
> 
> Am I missing something?
> 
> regards,
> Stefan