I want to be able to specify in my MongoDB query to, for each document, return the number of elements in a specific sub field (var_2 in this case), instead of the whole array. Example document:
{
"_id": "abc123",
"var_1": "A",
"var_2": [
"A",
"B",
"C"
]
}
I have tried this but it returns the whole array:
db.collection.find({var_1: "A"}, {var_1: 1, var_2: 1})
Desired output:
{
"_id": "abc123",
"var_1": "A",
"var_2": 3
}
Thanks in advance!