以下のクエリをmongodb3.6で試すことができます 以上
db.collection.find({
"$expr": {
"$gte": [{ "$dateFromString": { "dateString": "$date" }}, start.toDate() ],
"$lt": [{ "$dateFromString": { "dateString": "$date" }}, end.toDate() ]
}
}).count()
または集計あり
db.collection.aggregate([
{ "$addFields": {
"date": {
"$dateFromString": {
"dateString": "$date"
}
}
}},
{ "$match": { "date": { "$gte": start.toDate(), "$lt": end.toDate() }}},
{ "$count": "count" }
])