mongodb 查询某一天所有信息的3种方法,根据日期查询
// mongodb的查询真让人难以琢磨,就查询单天信息,都需要花费一番功夫才行。 // 第一种方式: coll.aggregate([ {$project:{sendDate: {$substr: ['$sendTime', 0, 10]}, sendTime: 1, content:1}}, {$match:{sendDate: '2015-07-05'}}, ]) // 第二种方式(第二种的变异): coll.aggregate([ {$match: {'sendTime': {'$gte': new Date('2015-07-05'), '$lt': new Date('2015-07-06')}}} // 第三中方式(第二种的变异): coll.aggregate([ {$match: {'sendTime': {'$gte': new Date('2015-07-05 00:00:00'), '$lte': new Date('2015-07-05 23:59:59')}}}
// 查询结果如下(展示一种方式:其他展示略有不同): [ { _id: 5599b09bc16aac90e9fb7995, sendDate: '2015-07-05' }, { _id: 5599b161c16aac90e9fb7996, sendDate: '2015-07-05' }, { _id: 5599b161c16aac90e9fb7997, sendDate: '2015-07-05' } ]
$cmp | Returns: 0 if the two values are equivalent, 1 if the first value is greater than the second, and -1 if the first value is less than the second. |
$eq | Returns true if the values are equivalent. |
$gt | Returns true if the first value is greater than the second. |
$gte | Returns true if the first value is greater than or equal to the second. |
$lt | Returns true if the first value is less than the second. |
$lte | Returns true if the first value is less than or equal to the second. |
$ne | Returns true if the values are not equivalent. |
更多实例应用扫码体验:
相关推荐
lbyd0 2020-11-17
BigYellow 2020-11-16
sushuanglei 2020-11-12
我心似明月 2020-11-09
zhushenghan 2020-11-09
sunnnyduan 2020-10-16
不要皱眉 2020-10-14
xiaohai 2020-09-29
songxiugongwang 2020-09-22
萌亖 2020-09-17
LuckyLXG 2020-09-08
sdmzhu 2020-09-01
mkhhxxttxs 2020-09-16
xiaohai 2020-09-16
newcome 2020-09-09
jaylong 2020-08-19
大秦铁骑 2020-08-19
thatway 2020-08-19