Jose
Jose

Reputation: 136

Is it possible to filter over nested objects on stream-chat?

stream-chat v6.7.3

When I connect a user besides id, name, and image, I'm adding my own properties as an object, like this:

await client.connectUser({
            id: 'jose',
            name: 'pepe',
            image:'https://i.imgur.com/YEGTFwf.jpeg',
            myObject:{
                'id':1,
                'categoria':'writer'
            }
        },
        client.devToken('jose'));

but then when I try to query the user it simply returns an empty array, I'm trying like this:

await client.queryUsers({"myObject.categoria":"writer"});

I have tried over id, or other properties inside the user object and the filter works like a charm, so I'm wondering if this is the right way to do the query. Or if is it possible to query over an inside object.

Upvotes: 2

Views: 590

Answers (2)

ferhatelmas
ferhatelmas

Reputation: 3978

Only top level is supported. Objects needs flattening. Arrays have more tools $contains and $in.

For example:

Let's say data is colors: ['yellow', 'black']

then colors: {$contains: ['yellow', 'white']} can find it.

Upvotes: 1

Jose
Jose

Reputation: 136

According to stream support, "Currently the API can't filter over nested objects like this, only values in the top level."

Upvotes: 1

Related Questions