简体   繁体   English

如何使用 Spring Boot 中的特定日期范围和聚合从 MongoDB 数据库中检索数据?

[英]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:我尝试过的方法:

  1. I used the aggregation with less than and greater than clause in MongoDB.我在 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.我还使用了 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.

相关问题 如何使用电子邮件从Firebase实时数据库检索数据? - How to retrieve data using email from firebase realtime databse? 如何在MongoDB的Spring Boot上使用聚合 - How to use aggregation on spring boot with mongodb Spring Data MongoDB聚合与日期匹配 - Spring Data MongoDB Aggregation Match with Date Spring 数据 MongoDB 聚合匹配日期和平均值 - Spring Data MongoDB Aggregation Match with Date and average 使用Spring Boot时来自mongodb的数据 - Data from mongodb when using Spring boot 如何在 Spring 启动时使用 Date 从数据库中获取数据? - How to fetch data from database by using Date in Spring boot? 如何使用 Java 或 Spring Boot 从 Mongodb 检索 HTML 中显示图像 - How to display an image in HTML retrieve from Mongodb using Java or Spring boot 如何使用Spring Boot从MongoDB中的ArrayList传递的顺序检索对象列表? - How to retrieve list of objects in sequence order that is passed from an ArrayList in MongoDB using Spring Boot? 如何使用Spring Data Aggregation输出到MongoDB集合 - How to output to MongoDB collection using Spring Data Aggregation 如何从Spring数据MongoDB中的AggregationOperation列表创建聚合? - How to create an Aggregation from a list of AggregationOperation in Spring data MongoDB?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM