使用"$ gte"和"$ lte"时Pymongo返回错误

mr-*_*-sk 1 python datetime epoch mongodb pymongo

我试图从mongo中选择(使用pymongo),查询纪元时间戳.我的数据库中的一个样本(为了简洁起见):

{
    "_id": "",
    "tweet": {
        "iso_language_code": "en",
        "to_user_name": null,
        "timestamp": 1355325948,
        "created_at": "Wed, 12 Dec 2012 15:25:48 +0000"
    }
}
Run Code Online (Sandbox Code Playgroud)

以及代码和python控制台中的查询:

<console>
db.tweets.find({
    "tweet.timestamp":{'$gte':1355391000},
    "tweet.timestamp":{'$lte':1355414400}
})

<code>
cursor = db.tweets.find({"tweet.timestamp":{'$gte':startEpoch},
                         "tweet.timestamp":{'$lte':endEpoch}})
Run Code Online (Sandbox Code Playgroud)

哪个是 星期四,2012年12月13日09:30:00 GMT星期四,2012年12月13日16:00:00 GMT.

它应该说,让我所有的推文gte这个intlte这个其他int.但是,它会返回所有内容 - 它似乎根本不限制这些值.

例如,返回此条目,时间戳为:1355325948,即:Wed,12 Dec 2012 15:25:48 GMT

另外,我理解使用params列表查找(...)是一个隐含的AND.

天哪!

Joh*_*yHK 6

您的查询对象中不能有两个具有相同名称的键.你必须将它们组合成一个像这样的值:

cursor = db.tweets.find({"tweet.timestamp":{'$gte':startEpoch, '$lte':endEpoch}})
Run Code Online (Sandbox Code Playgroud)