I am facing a challenge in building a table with values from an Array of objects retrieved from mongodb. I am able to fetch every value, but I actually only need a specific value.
Here is the query I have constructed:
router.get("/arquiveExpense", ensureAuthenticated, (req, res) => {
House.find({
userID: req.user.id,
expensesHouse: { $elemMatch: { status: "Private" } }
}).then(house => {
console.log(house);
res.render("houses/arquiveExpense", {
house: house
});
});
});
My objective is to extract the specific value from the 'expensesHouse' with status 'Private'.
In my handlebars file, the structure looks like this:
<tbody>
<tr>
{{#each house}}
<td>{{expenseType}}</td>
<td>{{price}}€</td>
<td>{{payAt}}</td>
<td>{{formatDate date 'MMMM Do YYYY'}}</td>
<td>
<a href="/houses/showExpense/{{id}}" id="detailsExpense"
class="btn btn-outline-light mb-3"><i class="fas fa-eye mr-2"></i>Details
</a>
<td>
<a href="/houses/editExpense/{{id}}" id="editExpense" class="btn btn-outline-light mb-3"><i
class="fas fa-edit mr-2"></i>Edit
</td>
</tr>
{{else}}
<p>No expenses</p>
{{/each}}
</tbody>
Upon rendering the handlebars template, the output can be viewed here.
The Schema structure is as depicted here.
My goal is to display on the web page the value from 'expensesHouse' with the Status 'Private'.
How can I modify my code to retrieve this specific value only?