In mongoDB, get number of array items in a document — and why didn’t I just use sql to begin with!?
I have a document that looks like this …
{
"age": 18,
"role": "client",
"email": "[email protected]",
"name": "down",
"answers": [{
"_id": {
"$oid": "61aa9a5e467fa9109b745d21"
},
"position": 2,
"scale": 9,
"slider": 0
}, {
"_id": {
"$oid": "61aa9d3cd3912610d1196e40"
},
"position": 2,
"scale": 9,
"slider": 0
}],
"createdAt": {
"$date": "2021-11-01T20:26:05.225Z"
},
"updatedAt": {
"$date": "2021-12-03T22:42:04.861Z"
},
"__v": 0
}
Using mongoose, how do I get the number of array elements in the answers array?