how to query a custom object within a channel

219 Views Asked by At

I have this custom data in the channel

{
 channelHashId: '111122222',
 cid: '111111',
 data: {
   custom: {
     name: "testing"
   }
 }
 address: "my address",
}

i tried

const filter = { type: 'messaging', data: { custom: { name: 'testing' }  } };
const sort = [{ last_message_at: -1 }]; 

const channels = await chatClient.queryChannels(filter, sort, {
    watch: true, // this is the default
    state: true,
});

but i get an error 'invalid field operation',

but if i do

const filter = { type: 'messaging', address: 'my address'  } };
const sort = [{ last_message_at: -1 }]; 

const channels = await chatClient.queryChannels(filter, sort, {
    watch: true, // this is the default
    state: true,
});

it works fine

please help

1

There are 1 best solutions below

1
On BEST ANSWER

Use queryMembers (see docs) instead of queryChannels.

Under the hood, since the data field is of a reference type (an object), queryChannels would compare the reference instead of the content of your object.