日期范围查询失败的推文的MongoDB数据库 [英] Date range query failing for MongoDB database of tweets

查看:70
本文介绍了日期范围查询失败的推文的MongoDB数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对mongo数据库中的一系列tweet执行范围查询.由于某些原因,以下查询将起作用:

I'm trying to perform a range query for a collection of tweets in a mongo database. For some reason the following query will work:

db.posts.find({'created_at': {$gte:"Fri Nov 25 00:00:00 +0000 2011", $lt:"Fri Nov 25 23:59:59 +0000 2011"}})

但以下内容不会:

db.posts.find({'created_at': {$gte:"Thu Nov 24 00:00:00 +0000 2011", $lt:"Fri Nov 25 23:59:59 +0000 2011"}})

我正在将tweet作为JSON对象直接输入数据库,所以这应该不是问题,对吗?

I'm entering the tweet as a JSON object directly into the database, so this shouldn't be an issue, correct?

推荐答案

您需要确保使用的是实际的Date值,而不是字符串.例如:

You need to make sure you are using real Date values, not strings. For example:

var from = ISODate("2011-11-24")
var to = ISODate("2011-11-25T23:59:59")
db.posts.find({ created_at : { $gte : from, $lt : to } })

除了确保查询使用的是真实的日期值外,还要确保存储的数据也包含真实的日期值.

Besides making sure your queries are using real Date values, make sure your stored data contains real Date values also.

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

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