{
"_id" : "62860d15ae6cd23352fa3683",
"chapterName" : "chap1",
"groupId" : ObjectId("5f06cca74e51ba15f5167b86"),
"teamId" : ObjectId("6069a6a9a0ccf704e7f4b537"),
"topicsList" : {
"fromDate" : "26-05-2022",
"fromDateString" : 20220526,
"toDate" : "29-05-2022",
"toDateString" : 20220529,
"topicId" : "62860d15ae6cd23352fa3684",
"topicName" : "1"
},
"userId" : ObjectId("6069a5daa0ccf704e7319d16")
}
{
"_id" : "62860d15ae6cd23352fa3683",
"chapterName" : "chap1",
"groupId" : ObjectId("5f06cca74e51ba15f5167b86"),
"teamId" : ObjectId("6069a6a9a0ccf704e7f4b537"),
"topicsList" : {
"fromDate" : "01-06-2022",
"fromDateString" : 20220601,
"toDate" : "03-06-2022",
"toDateString" : 20220603,
"topicId" : "62860d15ae6cd23352fa3685",
"topicName" : "2"
},
"userId" : ObjectId("6069a5daa0ccf704e7319d16")
}
{
"_id" : "62860d15ae6cd23352fa3686",
"chapterName" : "chap2",
"groupId" : ObjectId("5f06cca74e51ba15f5167b86"),
"teamId" : ObjectId("6069a6a9a0ccf704e7f4b537"),
"topicsList" : {
"fromDate" : "02-07-2022",
"fromDateString" : 20220702,
"toDate" : "04-07-2022",
"toDateString" : 20220704,
"topicId" : "62860d15ae6cd23352fa3687",
"topicName" : "1"
},
"userId" : ObjectId("6069a5daa0ccf704e7319d16")
}
I wanted to check fromDateString >= 20220526 and toDateString <= 20220526
the query used is
db.VW_SYLLABUS_PLAN_DB.find({$expr: {$and: [{$gte: ["topicsList.fromDateString", 20220526]}, {$lte: [20220526,"topicsList.toDateString"]}]}}).pretty()
The output I’m getting
{
"_id" : "62860d15ae6cd23352fa3683",
"chapterName" : "chap1",
"groupId" : ObjectId("5f06cca74e51ba15f5167b86"),
"teamId" : ObjectId("6069a6a9a0ccf704e7f4b537"),
"topicsList" : {
"fromDate" : "26-05-2022",
"fromDateString" : 20220526,
"toDate" : "29-05-2022",
"toDateString" : 20220529,
"topicId" : "62860d15ae6cd23352fa3684",
"topicName" : "1"
},
"userId" : ObjectId("6069a5daa0ccf704e7319d16")
}
{
"_id" : "62860d15ae6cd23352fa3683",
"chapterName" : "chap1",
"groupId" : ObjectId("5f06cca74e51ba15f5167b86"),
"teamId" : ObjectId("6069a6a9a0ccf704e7f4b537"),
"topicsList" : {
"fromDate" : "01-06-2022",
"fromDateString" : 20220601,
"toDate" : "03-06-2022",
"toDateString" : 20220603,
"topicId" : "62860d15ae6cd23352fa3685",
"topicName" : "2"
},
"userId" : ObjectId("6069a5daa0ccf704e7319d16")
}
{
"_id" : "62860d15ae6cd23352fa3686",
"chapterName" : "chap2",
"groupId" : ObjectId("5f06cca74e51ba15f5167b86"),
"teamId" : ObjectId("6069a6a9a0ccf704e7f4b537"),
"topicsList" : {
"fromDate" : "02-07-2022",
"fromDateString" : 20220702,
"toDate" : "04-07-2022",
"toDateString" : 20220704,
"topicId" : "62860d15ae6cd23352fa3687",
"topicName" : "1"
},
"userId" : ObjectId("6069a5daa0ccf704e7319d16")
}
any ways to get only one document in this way
{
"_id" : "62860d15ae6cd23352fa3683",
"chapterName" : "chap1",
"groupId" : ObjectId("5f06cca74e51ba15f5167b86"),
"teamId" : ObjectId("6069a6a9a0ccf704e7f4b537"),
"topicsList" : {
"fromDate" : "26-05-2022",
"fromDateString" : 20220526,
"toDate" : "29-05-2022",
"toDateString" : 20220529,
"topicId" : "62860d15ae6cd23352fa3684",
"topicName" : "1"
},
"userId" : ObjectId("6069a5daa0ccf704e7319d16")
}