【问题标题】:How to retrieve data from MongoDB databse using specific date range and aggregation in Spring Boot?如何在 Spring Boot 中使用特定日期范围和聚合从 MongoDB 数据库中检索数据?
【发布时间】:2019-08-19 08:22:14
【问题描述】:

我正在开发一个 Spring Boot 项目并使用 MongoDB 作为我的数据库。

有一个包含学生文档的studentDB数据库,该文档包含以下字段:

_id 、学生姓名、参加讲座、iso_dom、iso_dow、iso_month、iso_year、iso_week"。

学生档案

   _id             Object
   student_name    String
   attend_lecture  int
   iso_dom         int    date of the month ("1" January 2015)
   iso_dow         int    day of the week (Friday)
   iso_month       int    the month (1 stand for January)
   iso_year        int    year (2015)
   iso_week        int    week number (1)

我在这里尝试检索 2015 年 1 月 12 日至 2015 年 3 月 13 日期间有多少学生参加了讲座?

我尝试过的方法:

  1. 我在 MongoDB 中使用了带有小于和大于子句的聚合。

  2. 在检索 2015 年 1 月 12 日至 2015 年 3 月 13 日之间的所有日期时,我还使用了 part 子句的日期。

问题: 是否有任何可行的方法来检索 2015 年 1 月 12 日至 2015 年 3 月 13 日期间有多少学生参加了讲座?

示例:

学生档案

  "_id":"5c1639b3a1b32bb04547137f",

  "student_name":"MR. Rahul"

  "iso_dom":12,

  "iso_dow":3,

  "iso_month":1,

  "iso_week":12,

  "isp_year":2018,

  "attend_lecture":5

【问题讨论】:

    标签: java mongodb spring-boot microservices aggregation


    【解决方案1】:

    插入新的关键日期,可以选择两个日期之间的文档,并使用聚合函数检索 2015 年 1 月 12 日至 2015 年 3 月 13 日期间参加讲座的学生人数。

    【讨论】:

      猜你喜欢
      • 2020-04-28
      • 2020-04-29
      • 2017-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      • 2018-02-05
      相关资源
      最近更新 更多