将此作为mongo find命令的输出
{
"cust" : NumberInt(8388),
"key" : "T_SUB_CAT",
"value" : "98",
"tag1" : "T_RECENT_SUB_CAT_1"
},{
"cust" : NumberInt(8388),
"key" : "T_SUB_CAT",
"value" : "109",
"tag1" : "T_RECENT_SUB_CAT_2"
},{
"cust" : NumberInt(8388),
"key" : "T_SUB_CAT",
"value" : "6",
"tag1" : "T_RECENT_SUB_CAT_3"
}
如何使用聚合和$ project来获得结果这个
{
"cust" : NumberInt(8388),
"T_RECENT_SUB_CAT_1" : "98",
"T_RECENT_SUB_CAT_2" : "109",
"T_RECENT_SUB_CAT_3" : "6"
}
请使用项目/汇总
帮助我非常感谢
答案 0 :(得分:0)
将所有结果放入var say cust2,
while(cust2.hasNext()){
var document = cust2.next(); db.<collection>.update(
{ cust: document.cust, tag1:document.tag1 },
{ cust:document.cust , tag1:document.tag1 ,
key:document.key, value:document.value },
{upsert:true}
) }