Hi,
I am having trouble accessing an associative array "toPostID" in the following aggregate statement:
I'd like to use a custom user variable to determine my group_by's key.
db.comments.aggregate([
{
'$group' : {
'_id' : {
'$let' : {
'vars' : {
'toPostID': {
'$literal': {id1: 123, id2: 456},
}
},
'in': '$$toPostID[$id]',
}
},
'comments': {
'$push': '$$CURRENT',
}
}
}
]);
Here is an example of a comment:
{
id: 'id1',
text: 'hello'
}
I get the error: toPostID[$id]' contains an invalid character for a variable name: '['"
Is there a way to evaluate the array access?
Thank you!