Reputation: 514
I can create a secondary index for this table:
{
contact: [
'[email protected]'
]
}
Like this: indexCreate('contact', {multi: true})
But can I create index for this:
{
contact: [
{
type: 'email',
main: true
value: '[email protected]'
}
{
type: 'phone'
value: '0735521632'
}
]
}
Secondary index would only search in objects whose type is 'email' and main is set to 'true'
Upvotes: 1
Views: 63
Reputation: 7184
Here's how you might create such an index:
table.indexCreate(
'email',
row => row('contact').filter({type: 'email'})('value'),
{multi: true})
This works by using a multi-index. When the multi: true
argument is passed to indexCreate
, the index function is expected to return an array instead of a single value. Every element in that array can be used to look up the document in the index (using getAll
or between
). If the array is empty, the document will not show up in the index.
Upvotes: 1