Your start date object should hold the current date time hours at 00:00:00.000 (milliseconds precision) and set the hours for today's date to 23:59:59.999:var start = new Date();start.setHours(0,0,0,0);var end = new Date();end.setHours(23,59,59,999);然后像往常一样在您的MongoDB查询运算符中传递修改后的日期对象:Then pass the modified date objects as usual in your MongoDB query operator:db.posts.find({created_on: {$gte: start, $lt: end}});如果您使用的是 momentjs 库,则可以使用 startOf() 和 endOf() 方法,用于当前时刻的当前日期对象,并将字符串'day'作为参数传递:If you are using the momentjs library, this can be done by using the startOf() and endOf() methods on the moment's current date object, passing the string 'day' as arguments:var start = moment().startOf('day'); // set to 12:00 am todayvar end = moment().endOf('day'); // set to 23:59 pm today 这篇关于Mongodb今天按日期查找创建的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-26 06:07
查看更多