mongo 时间格式化 查询,Mongodb:基于ISODate格式的时间查询

本文探讨如何在MongoDB中查询日期字段'YYYY-MM-DDT'位于04:00到08:00之间的文档,不考虑具体日期。通过使用聚合框架和$redact操作符,可以实现这个查询。示例展示了如何筛选出'小时'在4到8之间的文档。
摘要由CSDN通过智能技术生成

Suppose the sample documents in Mongodb database are as follows:

{ "date" : ISODate("2015-11-09T05:58:19.474Z") }

{ "date" : ISODate("2014-10-25T07:30:00.241Z") }

{ "date" : ISODate("2015-11-30T15:24:00.251Z") }

{ "date" : ISODate("2012-01-10T18:36:00.101Z") }

Expected:

{ "date" : ISODate("2015-11-09T05:58:19.474Z") }

{ "date" : ISODate("2014-10-25T07:30:00.241Z") }

Iam interested in finding the documents whose time in "date" field is between 04:00 and 08:00 irrespective of day,month and year. Indirectly query has to match any "YYYY-MM-DDT" in date field.

My approach would be, query all the documents within presumed duration of dates from node and then for each document that matched the query, compare the "date&#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值