I only want to get data with groups that match at least with one of those groupIDs. I have tried a few solutions but I still did it wrong. Assuming we have data like this.
const groupIDs = ['124', '245', '678', '999', '111'];
const data = [
{
_id: 'example:123',
_rev: 'example',
name: 'John',
groups: [
{ groupID: '124', type: 'ADMIN' },
{ groupID: '345', type: 'PRACTITIONER' },
{ groupID: '678', type: 'PATIENT' },
]
},
{
_id: 'example:456',
_rev: 'example2',
name: 'Yoda',
groups: [
{ groupID: '124', type: 'ADMIN' },
{ groupID: '345', type: 'PRACTITIONER' }
]
},
];
This is my attempt:
db.createIndex({
index: { fields: ['groups.[].groupID'] }
})
.then((result) => {
db.find({
selector: { groups.groupID: { $in: groupIDs } },
use_index: results.name
})
})