My current data structure looks like this:
[
{
name: "A",
upvotes: [
"a",
"b"
],
downvotes: [
"a",
"b",
"c"
]
},
{
name: "B",
upvotes: [
"a"
],
downvotes: [
"a",
"b",
"c"
]
}
]
My goal is to retrieve the object with the highest number of votes. This is determined by calculating the difference between the size of the upvotes and downvotes arrays, such as
(size(upvotes) - size(downvotes))
.
For example, in this case, Object A has the highest number of votes with a calculation of ( 2 - 3 = -1)
.
Is there a way to achieve this using mongodb aggregation?
Thank you in advance for your assistance!