db.TruckUsers.group({
key:{PhoneNumber:true},
initial:{Count:0},
reduce:function(doc,prev)
{
if (!prev.PhoneNumber)
{
prev.PhoneNumber = doc.PhoneNumber;
prev.Count = 1;
}
else if(doc.PhoneNumber == prev.PhoneNumber)
{
prev.Count++;
}
},
finalize:function(doc)
{
for(i in doc.Count)
{
if (doc.Count > 1)
{
doc.NewPhoneNumber = doc.PhoneNumber;
doc.NewCount = doc.Count;
}
}
delete doc.PhoneNumber;
delete doc.Count;
}
})
我想只顯示Count>1的記錄,但不知道如何下手,現在的這個結果會把所有的記錄都會顯示出來,如下:
"28" : {},
"29" : {},
"30" : {},
"31" : {},
"32" : {},
"33" : {},
"34" : {},
"35" : {},
"36" : {},
"37" : {},
"38" : {},
"39" : {},
"40" : {},
"41" : {
"NewPhoneNumber" : "18217039***",
"NewCount" : 3
},