My $lookup operation on schemas is always returning an empty array. What could be causing this issue?
Result Collection
const resultSchema = new mongoose.Schema({
trial: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Trial',
required: true
}
});
Trial Collection
const trialSchema = new mongoose.Schema({
name: {
type: String,
required: true
}
});
Aggregate
Result.aggregate([
{
$lookup: {
from: 'trial',
localField: 'trial',
foreignField: '_id',
as: 'x'
}
}
])
.exec()
.then(results => ({ results }))
However, despite following the correct syntax, "x" always ends up as an empty array in the final output.