I was wondering what is the difference between $ and $$ in MongoDB.
For example:
'$sum': {
'$map': {
'input': '$data',
'as': 'currentData',
'in': { '$size': '$$currentData.d' }
}
}
What if I will use $ instead of $$ in $$currentData.d.
$ is referred to the root document fields where as $$ referred to the variable names.
{
"$sum": {
"$map": {
"input": "$data",
"as": "currentData",
"in": { "$size": "$$currentData.d" }
}
}
}
Here '$data' is the document array field and the $$currentData is the variable taken in the as expression of $map aggregation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With