I have an other question regarding the filtering, nested denormalization so I don’t want to open a new thread.
Suppose that given the above example I have an other 1-N relationship between the “Employees” and “Pets” collections where the Pets have a String field called “type” which can be “dog” or “cat”.
Lets say that I’d like to find only the companies that have employees who have dogs.
Would it be possible?
I tried something like this but I didn’t get what I wanted:
//Companies->Employees link
Companies.addLinks({
'employees': {
collection: Employees,
inversedBy: 'company',
denormalize: {
body: {
pets: {
type: 1
}
},
field: 'employeesCache',
}
}
})
//Companies<-Employees->Pets link
Employees.addLinks({
'pets': {
collection: Pets,
inversedBy: 'owner',
},
'company': {
type: 'one',
collection: Companies,
field: 'companyId'
}
})
//Pets->Employees link
Pets.addLinks({
'owner': {
type: 'one',
collection: Employees,
field: 'ownerId'
}
})
Whenever I try to do a query based on “employeesCache” it’s not working as I would expect it to be.
Is something like this possible with grapher or should I modify my database?
I also tried to do a regular query like this:
Companies.createQuery({
employees: {
pets: {
$filters: {
type: 'dog',
},
name: 1,
type: 1
}
}
});
But this also gives me the id’s of the companies, pets (without the employees/name, type fields) that did not match the query, can I avoid this somehow?
The queried documents look like this:
[ //I want this
{
_id: 'JFWbiRh9wG2ikEafr',
employees: [ [Object], [Object] ]
},
//I don't need this
{
_id: 'mJ5F93hMfmDgpXG8w'
}
]