Vai*_*hek 10 mongodb aggregation-framework
我可以使用'$'运算符引用MongoDB聚合管道中各个属性值的值.但是,如何访问(引用)整个文档?
更新:提供解释方案的示例.
这是我正在尝试做的一个例子.我有一些推文.每条推文都有一个成员"群集",这表明特定推文所属的群集.
{
"_id" : "5803519429097792069",
"text" : "The following vehicles/owners have been prosecuted by issuing notice on the basis of photographs on dated... http://t.co/iic1Nn85W5",
"oldestts" : "2013-02-28 16:11:32.0",
"firstTweetTime" : "4 hours ",
"id" : "307161122191065089",
"isLoc" : true,
"powertweet" : true,
"city" : "new+delhi",
"latestts" : "2013-02-28 16:35:05.0",
"no" : 0,
"ts" : 1362081807.9693,
"clusters" : [
{
"participationCoeff" : 1,
"clusterID" : "5803519429097792069"
}
],
"username" : "dtptraffic",
"verbSet" : [
"date",
"follow",
"prosecute",
"have",
"be"
],
"timestamp" : "4 hours ",
"entitySet" : [ ],
"subCats" : {
"Generic" : [ ]
},
"lang" : "en",
"fns" : 18.35967,
"url" : "url|109|131|http://fb.me/2CeaI7Vtr",
"cat" : [
"Generic"
],
"order" : 7
}
Run Code Online (Sandbox Code Playgroud)
因为,我的收藏中有几十条推文,我想通过'clusters.clusterID'对所有推文进行分组.基本上,我想写一个如下查询:
db.tweets.aggregate (
{ $group : { _id : '$clusters.clusterID', 'members' : {$addToSet : <????> } } }
)
Run Code Online (Sandbox Code Playgroud)
我想访问当前处理文档并在我放入上述查询的位置引用它.有谁知道怎么做?
Vol*_*lox 15
在文档中,我发现该$$ROOT表达式解决了这个问题.
来自DOC:http: //docs.mongodb.org/manual/reference/operator/aggregation/group/#group-documents-by-author
| 归档时间: |
|
| 查看次数: |
4194 次 |
| 最近记录: |