【发布时间】:2014-12-16 23:11:44
【问题描述】:
用 Java 编写一个 mongoDB“查询和更新”。
mongoDB 集合(名称:reduce)结果(map-reduce 结果)如下所示:
值域:
{ "value" :
{
"User_Name" : "Mitchamoreagent",
"tweets" : ["RT Perspectives:
Texas Insurer of Last Resort Charts Course Through Reform Law", "RT Texas sale
s tax-free weekend set for Aug. 19-21", "RT The New Normal: Billion-Dollar", "R
T Austin Water is responding to a 12-inch water main leak at Burnet Rd. and And
erson Lane in North Austin."]
}
}
试图找到所有推文中包含“单词”的用户名,我可以使用正则表达式来指定。
为了实现这一点,我尝试了 AggregationOutput,它适用于简单的情况。但是这个结构,我是打不通的。
代码:
DBObject match = new BasicDBObject("$match",new BasicDBObject("value",new BasicDBObject("tweets", new BasicDBObject("$regex",".*Texas.*"))));
DBObject fields = new BasicDBObject("_id", 0);
DBObject nest = new BasicDBObject("value", new BasicDBObject("User_ID", 1));
fields.put("value", 1);
DBObject project = new BasicDBObject("$project", fields );
AggregationOutput output = tweets.aggregate( match, project);
这里 'Texas' 是我要查找的单词,我希望输出 [Mitchamoreagent].
但输出始终是noRowsReturned异常。
【问题讨论】:
标签: java regex mongodb mapreduce aggregation-framework