I have a javascript loop that does the specific task of looping through a javascript hash and calling an aggregate across my collection.
I managed to insert the variable into the aggregate request for the $ match function, but I cannot for the $ project function.
I want to combine hash keys, and then display the hash values ββin combination with the values ββalready in the document that I just matched. These hash values ββand label were not specified in the document in advance.
var cmtss = {}; for (var item in cursor['result']) { var prov = cursor['result'][item]['prov_group']; cmtss[cursor['result'][item]['name']] = prov; } for (var item in cmtss) { var cmts = "$" + cmtss[item]; result = db.modems.aggregate( { $match : { cmts: item } } , { $project : { ip : "$ip", model : "$model", cmts : "$cmts", prov_group : cmts } } ); printjson(result); }
As you can see, I include $ match, where I want the cmts field to match the provided key. But with these matches, I want to display 3 fields, including the new field that I am adding, but its value is the hash value from cmts. I tried with and without the $ operator to value. It just does not display prov_group at all in the resulting documents.
Do I need to use $ add somehow?
source share