Can someone please help me to make a union query:
I have all of the jobs that were created between a time period.
[{
_id: '61be471835364400005ee66a',
created: '2021-12-18T20:39:52.279Z',
company: '61be44cb8c18cd0000be2048'
}]
I got this doing an aggregate query:
const jobs = await Job.aggregate([
{$match: ...},
{$project: ...},
]);
I have a collection of companies, and am trying to get the COMPANY name to be pulled over into the query, rather than having to get it client side. I have the _id already in the aggregate query result. I have been trying to do this:
const jobs = await Job.aggregate([
{$match: ...},
{$project: ...},
{$lookup: {
from: 'Company',
localField: 'company',
foreignField: '_id',
as: 'result'
};
]);
I was thinking that this would 1) get the Company that has an _id that matches our ‘company’ object ID above and 2) save that in the result field. There is nothing there, despite the object id being a match! Could someone please help walk me through how this should work? I could do it very easily I think in SQL.