在MongoDB中,可以使用`$gte`(大于等于)与`$lt`(小于)操作符来查询今天的数据。以下是一个示例查询今天数据的代码:
```javascript
consttoday=newDate();
today.setHours(0,0,0,0);
consttomorrow=newDate(today);
tomorrow.setDate(today.getDate()+1);
db.collection('yourCollection').find({
createdAt:{
$gte:today,
$lt:tomorrow
}
});
```
这个查询会查找`yourCollection`集合中`createdAt`字段值在今天00:00:00和明天00:00:00之间的数据。要查询其他字段,请将`createdAt`替换为您要查询的字段名。
版权声明:xxxxxxxxx;
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态