导读:
MongoDB是一种文档数据库,它以JSON格式存储数据 。在这篇文章中,我们将学习如何查询当天的文章 。我们将使用MongoDB的聚合管道来实现这个目标 。
总结:
要查询当天的文章,我们需要使用MongoDB的聚合管道 。首先,我们需要使用$match操作符过滤出今天发布的文章 。接下来,我们使用$sort操作符按照文章发布时间排序 。最后,我们使用$project操作符选择我们感兴趣的字段 。下面是完整的代码:
1. db.articles.aggregate([
2. {
3. $match: {
4. publish_date: {
5. $gte: new Date(new Date().setHours(0, 0, 0, 0)),
6. $lt: new Date(new Date().setHours(23, 59, 59, 999))
7. }
8. }
9. },
10. {
11. $sort: {
12. publish_date: -1
13. }
14. },
15. {
16. $project: {
17. _id: 1,
18. title: 1,
19. author: 1,
20. publish_date: 1
21. }
22. }
23. ])
【mongodb 日期查询 mongodb查询当天】这个聚合管道会返回一个包含所有今天发布的文章的数组 。每篇文章都有_id、title、author和publish_date字段 。
- mysql子查询和连接查询 mysql子查询插入
- Mysql使用索引查询 mysql使用round
- mongodb 更新子文档 mongodb数据文件无法新建
- 客户端无法连接到异速联服务器 客户端无法连接mongodb
- mongodb大公司案例 MongoDB公司怎么样
- mongodb查看数据库大小 查看mongodb集群容量
- 无法启动mongodb 1053 安装mongodb显示没有启动权
- mongodb用来存储什么 mongodb适合存储对象吗
- mongodb数据丢失原因 为什么mongodb数据库一直在加载中
- mongodb查询字符串字段包含 mongodb查询字段不为空
