简体   繁体   中英

How to retrieve data from MongoDB databse using specific date range and aggregation in Spring Boot?

I am working on a spring boot project and using MongoDB as my database.

There is studentDB database which contains a student document and that documents contain the following fields:

_id , student_name, attend_lecture, iso_dom, iso_dow, iso_month, iso_year, iso_week".

student document

   _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)

Here I am trying to retrieve how many students attended lectures in the date range between 12 January 2015 to 13 March 2015?

Methods I have Tried:

  1. I used the aggregation with less than and greater than clause in MongoDB.

  2. I also used the date of the part clause while I retrieved all the dates between 12 January 2015 to 13 March 2015.

Problem: Is there any feasible way to retrieve how many students attended lectures in the date range between 12 January 2015 to 13 March 2015?

Example:

student document

  "_id":"5c1639b3a1b32bb04547137f",

  "student_name":"MR. Rahul"

  "iso_dom":12,

  "iso_dow":3,

  "iso_month":1,

  "iso_week":12,

  "isp_year":2018,

  "attend_lecture":5

插入新的关键日期,提供在两个日期之间选择文档的选项,并使用聚合函数检索在 2015 年 1 月 12 日至 2015 年 3 月 13 日之间的日期范围内有多少学生参加了讲座。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM