Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用嵌套Json进行聚合_Java_Mongodb_Spring Boot - Fatal编程技术网

Java 使用嵌套Json进行聚合

Java 使用嵌套Json进行聚合,java,mongodb,spring-boot,Java,Mongodb,Spring Boot,前面我的mongodb文档如下所示 { "_id" : ObjectId("5880f010706358aab7a290af"), "user_id" : "2", "timezone" : "5.5" } 我下面的代码运行良好 private void getData(String id, String name) throws Exception { Aggregation aggregation = newAggregation( match(C

前面我的mongodb文档如下所示

{
   "_id" : ObjectId("5880f010706358aab7a290af"),
   "user_id" : "2",
   "timezone" : "5.5" 
}
我下面的代码运行良好

 private void getData(String id, String name) throws Exception {
     Aggregation aggregation = newAggregation(
     match(Criteria.where("user_id").is(id)),
     group("timezone").count().as("total"));

     AggregationResults<MongoResultCount> groupResults = mongoTemplate.aggregate(aggregation, "user_log", MongoResultCount.class);
     List<MongoResultCount> resultList = groupResults.getMappedResults();
  }

private class MongoResultCount {
     private String _id;
     private long total;
    }
我如何实现之前的目标。我搜索了一个解决方案,但尚未找到。

用于访问字段

差不多

Aggregation aggregation = newAggregation(
     match(Criteria.where("user_id").is(id)),
     group("meta_data.user_data.timezone").count().as("total"));

name
变量的值是多少?@Veeram很抱歉给您带来不便。我编辑那个。
Aggregation aggregation = newAggregation(
     match(Criteria.where("user_id").is(id)),
     group("meta_data.user_data.timezone").count().as("total"));