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' } ]

 

NameDescription
$cmpReturns: 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.
$eqReturns true if the values are equivalent.
$gtReturns true if the first value is greater than the second.
$gteReturns true if the first value is greater than or equal to the second.
$ltReturns true if the first value is less than the second.
$lteReturns true if the first value is less than or equal to the second.
$neReturns true if the values are not equivalent.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值