db.absences.insert([
{ \"_id\" : 1, \"student\" : \"Ann Aardvark\", sickdays: [ new Date (\"2018-05-01\"),new Date (\"2018-08-23\") ] },
Because you are trying to use the $lookup features (syntax) from MongoDB v3.6 on MongoDB v3.4
The MongoDB v3.4 $lookup syntax:
{
$lookup:
{
from: <collection to join>,
localField: <field from the input documents>,
foreignField: <field from the documents of the "from" collection>,
as: <output array field>
}
}
The MongoDB v3.6 $lookup syntax:
{
$lookup:
{
from: <collection to join>,
let: { <var_1>: <expression>, …, <var_n>: <expression> },
pipeline: [ <pipeline to execute on the collection to join> ],
as: <output array field>
}
}
https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/
In $lookup you could just join the collectionfirst and doing the match, project and etc later after lookup. And you should have the foreign field that referring to holidays collection.
Like :
{
$lookup:
{
from: "holidays",
localField: "holidaysID", //yourLocalfield, it is local field in absences. you should have it to join 2 collections
foreignField : "_id", //theforeignfield, it is _id in the holidays
as: "holidays"
}
},{ $match: { year: 2018 } },
{ $project: { _id: 0, date: { name: "$name", date: "$date" } } },
{ $replaceRoot: { newRoot: "$date" } }
Hope it helps.