Dakota Sorenson
04/11/2024, 10:16 PMtag_ids
on the contact, or would I need to build another collection like contact_tags
for instance that has a reference to contacts
and a reference to tags
?
I was able to create the collection with this field and fill the data, but I'm having trouble getting the queries to work. I'm guessing my syntax might be wrong or maybe it's not possible?
let searchParams = {
q: '*',
query_by: '',
filter_by: '$tags(id:*)',
include_fields: '$tags(*, strategy: nest_array)',
page: 1,
per_page: 50,
// sort_by: '$tags(name:asc)',
};
Harpreet Sangar
04/12/2024, 4:51 AMsort_by
?Dakota Sorenson
04/12/2024, 1:39 PMHarpreet Sangar
04/12/2024, 1:40 PMsort_by
.Harpreet Sangar
04/12/2024, 1:43 PMDakota Sorenson
04/12/2024, 1:44 PMDakota Sorenson
04/12/2024, 1:45 PMHarpreet Sangar
04/12/2024, 7:08 PMinclude_fields: $tags(*)
should be enough.Dakota Sorenson
04/12/2024, 7:12 PMinclude_fields: '$tags(*, strategy: nest_array)'
as well and the query worked but didn't include the tagsDakota Sorenson
04/12/2024, 7:12 PMHarpreet Sangar
04/12/2024, 8:02 PMcontacts
collection? Especially the definition of contact_card
Dakota Sorenson
04/15/2024, 1:30 PMtag_names
in the meantime. tag_ids
is the field I tried to add the reference to (I commented it out in the schema)
let contactsSchema: CollectionCreateSchema = {
name: collectionName,
enable_nested_fields: true,
fields: [
{ name: 'account_id', type: 'string', optional: true, sort: false },
{ name: 'authorized_account_ids', type: 'string[]', optional: true, sort: false },
{ name: 'added_at', type: 'int64', optional: true, sort: true },
{
name: 'contact_card.associated_card_id',
type: 'string',
optional: true,
sort: false,
},
{
name: 'contact_card.associated_card_name',
type: 'string',
optional: true,
sort: true,
},
{ name: 'contact_card.company', type: 'string', optional: true, sort: true },
{
name: 'contact_card.contact_card_id',
type: 'string',
optional: true,
sort: false,
},
{
name: 'contact_card.contact_id',
type: 'string',
optional: true,
sort: false,
},
{
name: 'contact_card.family_name',
type: 'string',
optional: true,
sort: true,
},
{
name: 'contact_card.given_name',
type: 'string',
optional: true,
sort: true,
},
{ name: 'contact_card.is_live_contact', type: 'bool', optional: true, sort: false },
{ name: 'contact_card.source', type: 'int32', optional: true, sort: false },
{ name: 'contact_card.tag_ids', type: 'string[]', optional: true, sort: false // reference: 'tags.id' },
{ name: 'contact_card.tag_names', type: 'string[]', optional: true, sort: false },
{ name: 'contact_card.title', type: 'string', optional: true, sort: true },
],
token_separators: ['+', '-', '@', '.'],
};
Dakota Sorenson
04/15/2024, 1:32 PMHarpreet Sangar
04/16/2024, 2:18 PMcontact_card
is an object in your document. If so, you can define
{ name: 'contact_card', type: 'object'}
Then the join should work.Dakota Sorenson
04/16/2024, 2:44 PMcontact_card
is an object in the doc! I can share a sample shortly
Is it best practice to define an object like that normally on the schema, or is it just needed for the joins? I have other schemas where I'm using an object in the doc so I'm wondering if I should update those to add the specific object type/definition as well?Dakota Sorenson
04/16/2024, 2:52 PM{
account_id: 'wzWAfweiojjfowij6Zgu9tVFuH3',
added_at: 1694119056432,
authorized_account_ids: [ 'wzWAfweiojjfowij6Zgu9tVFuH3' ],
contact_card: {
associated_card_id: 'JmSNJDOWIJOnlAcxao7L8',
associated_card_name: 'Work',
company: 'Fake Company Name',
contact_card_id: 'WRjMlAQFJIOWQJSpHBNDs',
contact_id: 'MR06iOxJ9WOKFPQwuSLm03',
given_name: 'Person',
family_name: 'Name',
source: 2,
tag_ids: [ 'fwoeufOUFEOWU' ],
tag_names: [ 'tag' ],
title: 'Person Title'
},
id: 'eagWJDOFIOQOdO9lLS0'
}
Harpreet Sangar
04/16/2024, 3:58 PMIs it best practice to define an object like that normally on the schema, or is it just needed for the joins?I've only tested the reference field inside an object where I declared the object field. I'm not sure why joins didn't work without it. I'll check this.
Dakota Sorenson
04/16/2024, 4:27 PM