Hi all!
I'm trying to aggregate some data and I run into a problem that seems really weird to me.
Consider the following queries:
#1
db.test.aggregate( {
$project: {
a: {
$let: {
vars: {var1: 1},
in: {$add: '$$var1'}
}
}
}
})
This returns the documents with value of a as: "a" : 1 as expected.
#2
db.test.aggregate( {
$project: {
a: {
$let: {
vars: {var1: 1},
in: {$add: ['$$var1','$$var1']}
}
}
}
})
This returns the documents with value of a as: "a" : 2 as well as expected.
So, logically, the following should also work, just like the above, and return a = 2
db.test.aggregate( {
$project: {
a: {
$let: {
vars: {var1: [1,1]},
in: {$add: '$$var1'}
}
}
}
})
But that would be too beautiful and doesn't work, returning an exception $add only supports numeric or date types, not Array
Can anyone explain to me what's the difference between example #2 and #3 - since technically, they should be evaluated to the same code?