I'm trying to build a query to fetch information from my mongoDB but I need to filter the results and only get the corresponding value.
This is the way I have tried until now. I need to match the expensesHouse._id with the id i will pass in the link.
router.get("/showExpense/:id", ensureAuthenticated, (req, res) => {
House.aggregate([
{
expensesHouse: {
$filter: {
input: "$expensesHouse",
as: "each",
cond: { $eq: ["$$each._id", req.params.id] }
}
}
}
]).then(house => {
console.log(house);
res.render("houses/showExpense", {
house: house
});
});
The following screen is the mongodb schema. I need to get every value from expensesHouse but only with the 'id' I pass need to match with the expensesHouse.ID
After the result I need to use them here in my handlebars
<form>
{{#each house}}
{{#each expensesHouse}}
<div class="form-group">
<label for="expenseType" class="text-dark">Expense Type</label>
<input type="text" class="form-control" name="expenseType" value="{{expenseType}}" disabled>
</div>
<div class="form-group">
<label for="description" class="text-dark">Description</label>
<input type="text" class="form-control" name="description" value="{{description}}" disabled>
</div>
<div class="form-group">
<label for="price" class="text-dark">Price</label>
<input type="text" class="form-control" name="price" value="{{price}}" disabled>
</div>
<div class="form-group">
<label for="status" class="text-dark">Price</label>
<input type="text" class="form-control" name="status" value="{{status}}" disabled>
</div>
{{/each}}
{{/each}}
</form>

expensesHouseneeds to be wrapped inside a$projectstageObjectIdobject instead of passing astring