mongodb:如何过滤掉今天创建的记录? [英] mongodb: how to filter out the records that created today?

查看:48
本文介绍了mongodb:如何过滤掉今天创建的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有类型为datetime.now()的时间戳记的集合:

I have a collection with a timestamp field of type datetime.now():

"chashi_ts" : ISODate("2012-06-12T16:08:22.645Z")

仅使用mongodb命令行,如何查找该字段的日期时间指向今天的记录?

With only mongodb commandline, how to find the records that the field's datetime points to today?

推荐答案

假设您可以获取当前日期....

Assuming you can get the current date....

// the start of the day (midnight)
begin_date_range = ISODate("2012-06-12T00:00:00Z");

// the start of the next day (at midnight)
// this can also be done with 11:59:59PM of the current date using $lte
end_date_range = ISODate("2012-06-13T00:00:00Z");

results = db.collection_name.where({"chashi_ts":{
              "$gte":begin_date_range,
              "$lt":end_date_range}
          );

这篇关于mongodb:如何过滤掉今天创建的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆