Implement Map-Reduce (1.4.3)
This commit is contained in:
parent
d5df23a8c3
commit
135c7dfd28
@ -56,6 +56,33 @@ public class DocumentQuery implements IDocumentQuery {
|
||||
|
||||
@Override
|
||||
public List<Document> getDocumentStatistics() {
|
||||
return null;
|
||||
MongoCollection<Document> collection = db.getCollection(COLL_LOCATION_DATA);
|
||||
|
||||
String map =
|
||||
"function() {" +
|
||||
"if (this.type === 'place') {" +
|
||||
"emit(this.category, 1);" +
|
||||
"}" +
|
||||
"}";
|
||||
|
||||
String reduce =
|
||||
"function(key, values) {" +
|
||||
"sum = 0;" +
|
||||
"values.forEach(value => {sum += value});" +
|
||||
"return sum;" +
|
||||
"}";
|
||||
|
||||
List<Document> result = new ArrayList<>();
|
||||
MongoCursor<Document> cursor = collection.mapReduce(map, reduce).iterator();
|
||||
|
||||
try {
|
||||
while (cursor.hasNext()) {
|
||||
result.add(cursor.next());
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user