According to your question, you want to receive documents of the current day from the mongodb collection . In the mongoDB shell, when you enter new Date()it, it gives you the current date with time, and this value always changes when you run the same new Date(), so your query probably looks like this:
db.collectionName.find({"start_date":new Date()}).pretty()
But I think that this query returns those documents that will be presented in your collection, but the same value of the current value Datemay not be presented in your documents. In this case, you should use the following
db.collectionName.find({"start_date":{"$lte":new Date()}}).pretty()
Or
db.collectionName.find({"start_date":{"$gte":new Date()}}).pretty()
year,month,day, aggregation $year, $month, $dayOfMonth $project, :
db.collectionName.aggregate({
"$project": {
"year": {
"$year": "$date"
},
"month": {
"$month": "$date"
},
"day": {
"$dayOfMonth": "$date"
}
}
}, {
"$match": {
"year": new Date().getFullYear(),
"month": new Date().getMonth() + 1, //because January starts with 0
"day": new Date().getDate()
}
})
, , year,month,day . $match
var currentDate = new Date()
{
"$match": {
"year": currentDate.getFullYear(),
"month": currentDate.getMonth() + 1,
"day": currentDate.getDate()
}
}