I have a specific document in my collection that I need help with:
{
"_id" : ObjectId("5b8aaaebf57de10e080c9151"),
"user_email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9cddcd4c9f9cddcd4c997dad6d4">[email protected]</a>",
"platforms_budget" : [
{
"_id" : ObjectId("5b8aaaebf57de10e080c9154"),
"platform_id" : "f_01",
"platform_name" : "Facebook"
},
{
"_id" : ObjectId("5b8aaaebf57de10e080c9153"),
"platform_id" : "i_01",
"platform_name" : "Instagram"
},
{
"_id" : ObjectId("5b8aaaebf57de10e080c9152"),
"platform_id" : "f_02",
"platform_name" : "Facebook_Adds"
}
],
"__v" : 0
}
My task is to locate a specific user using their email address under "user_email" and determine the length of the associated "platform_budget" array. In this instance, the expected array length is 3.
The function I am utilizing for this task is shown below:
var BudgetSchema = require('../models/Budget');
router.post('/temp', async function (req, res) {
var length = await BudgetSchema.aggregate(
[{ $match: { user_email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bacedfc9cefacedfc9ce94d9d5d7">[email protected]</a>" } }, { $unwind: "$platforms_budget" },
{ $project: { "platforms_budget.count": { $size: '$platforms_budget' } } }])
console.log(length);
})
Upon attempting to log the value of length, an empty array is returned.
I have reviewed similar solutions on websites like this one, but I am still unable to grasp what mistake I am making or how to access the size information from the response. Can anyone assist me in determining the size of the "platforms_budget" array?
Your guidance is greatly appreciated.