STUDY/Mongo DB

monogoDB - 특정 기간만 가져오는 쿼리

Jexists 2024. 5. 23. 22:06
2024년 데이터만 가져오기 (일년)
db.getCollection('collectionDB').aggregate([
 {
   "$match":{
     "datetime": {
       "$gte": time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
       "$lt":  time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
     },
   },
 },
])

 

2024년 1월 데이터 가져오기 (한달)

db.getCollection('collectionDB').aggregate([
 {
   "$match":{
     "datetime": {
       "$gte": time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
       "$lt":  time.Date(2024, 2, 1, 0, 0, 0, 0, time.UTC),
     },
   },
 },
])