[英]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.我正在开发一个 Spring Boot 项目并使用 MongoDB 作为我的数据库。
There is studentDB database which contains a student document and that documents contain the following fields:有一个 studentDB 数据库,其中包含一个学生文档,并且该文档包含以下字段:
_id , student_name, attend_lecture, iso_dom, iso_dow, iso_month, iso_year, iso_week". _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?在这里,我试图检索在 2015 年 1 月 12 日至 2015 年 3 月 13 日之间的日期范围内有多少学生参加了讲座?
Methods I have Tried:我尝试过的方法:
I used the aggregation with less than and greater than clause in MongoDB.我在 MongoDB 中使用了小于和大于子句的聚合。
I also used the date of the part clause while I retrieved all the dates between 12 January 2015 to 13 March 2015.我还使用了 part 子句的日期,同时检索了 2015 年 1 月 12 日至 2015 年 3 月 13 日之间的所有日期。
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?问题:是否有任何可行的方法可以检索在2015年1月12日至2015年3月13日之间的日期范围内有多少学生参加了讲座?
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 日之间的日期范围内有多少学生参加了讲座。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.