我遇到了mongoDB中的聚合问题。我正在处理的数据结构是这样的: -
{
"_id" : ObjectId("4f16fe11d1e2d32371072aa0"),
"body" : " \nHi Kate, per our discussion on yesterday about the $15.00 f
lat fee on Tom's \nand Mark's deals, here is Bloomberg's response. Please pass
this info to all \nof our traders. Please let me know what the response is from
them.\n\nThanks\n\n\n---------------------- Forwarded by Evelyn Metoyer/Corp/En
ron on 04/17/2001 \n02:34 PM ---------------------------\n\n\n\"PAUL CALLAHAN, B
LOOMBERG/ NEW YORK\" <PCALLAHAN2@bloomberg.net> on 04/17/2001 \n02:28:57 PM\nTo:
Evelyn.Metoyer@enron.com\ncc: \n\nSubject: Commission\n\n\nEvelyn, as of April
16, 2001 our charge for Spot trades is a flat fee of\n$15/trade.\n\n\n",
"filename" : "3272.",
"headers" : {
"Content-Transfer-Encoding" : "7bit",
"Content-Type" : "text/plain; charset=us-ascii",
"Date" : ISODate("2001-04-17T14:33:00Z"),
"From" : "evelyn.metoyer@enron.com",
"Message-ID" : "<33504483.1075841847839.JavaMail.evans@thyme>",
"Mime-Version" : "1.0",
"Subject" : "Commission for Bloomberg",
"To" : [
"kate.symes@enron.com"
],
"X-FileName" : "kate symes 6-27-02.nsf",
"X-Folder" : "\\kate symes 6-27-02\\Notes Folders\\Discussion th
reads",
"X-From" : "Evelyn Metoyer",
"X-Origin" : "SYMES-K",
"X-To" : "Kate Symes",
"X-bcc" : "",
"X-cc" : ""
},
"mailbox" : "symes-k",
"subFolder" : "discussion_threads"
}
数据库中有120477条记录。我应该找出那些倾向于彼此沟通最多(第二)的人。我写的查询如下:
db.messages.aggregate([{$project:{From:"$headers.From",To:"$headers.To",_id:0}
},{$unwind:"$headers.To"},{$group:{_id:{From:"$From",To:"$To"},number:{$sum:1}}}
,{$limit:3},{$sort:{number:-1}}]);
但它在某种程度上不起作用。