javascriptreactjsgetstream-iogetstream-chat

how to query a custom object within a channel


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


Solution

  • 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.