根据日期返回查询 [英] return query based on date

查看:78
本文介绍了根据日期返回查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mongodb中有这样的数据

I have a data like this in mongodb

{ 
    "latitude" : "", 
    "longitude" : "", 
    "course" : "", 
    "battery" : "0", 
    "imei" : "0", 
    "altitude" : "F:3.82V", 
    "mcc" : "07", 
    "mnc" : "007B", 
    "lac" : "2A83", 
    "_id" : ObjectId("4f0eb2c406ab6a9d4d000003"), 
    "createdAt" : ISODate("2012-01-12T20:15:31Z") 
}

我如何查询db.gpsdatas.find({'createdAt': ??what here??}),以便它从数据库中将上述数据结果返回给我?

How do I query db.gpsdatas.find({'createdAt': ??what here??}), so that it returns the above data result to me from the db?

推荐答案

您可能要进行范围查询,例如,在给定日期之后创建的所有项目:

You probably want to make a range query, for example, all items created after a given date:

db.gpsdatas.find({"createdAt" : { $gte : new ISODate("2012-01-12T20:15:31Z") }});

我使用的是$gte(大于或等于),因为它通常用于仅日期的查询,其中时间部分为00:00:00.

I'm using $gte (greater than or equals), because this is often used for date-only queries, where the time component is 00:00:00.

如果您真的想找到一个等于另一个日期的日期,则语法为

If you really want to find a date that equals another date, the syntax would be

db.gpsdatas.find({"createdAt" : new ISODate("2012-01-12T20:15:31Z") });

这篇关于根据日期返回查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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