【问题标题】:Pymongo returning incorrectly when using "$gte" and "$lte"Pymongo 在使用“$gte”和“$lte”时返回错误
【发布时间】:2012-12-04 04:21:16
【问题描述】:

我正在尝试从 mongo 中进行选择(使用 pymongo),查询纪元时间戳。 我的数据库中的一个样本是(为简洁起见):

{
    "_id": "",
    "tweet": {
        "iso_language_code": "en",
        "to_user_name": null,
        "timestamp": 1355325948,
        "created_at": "Wed, 12 Dec 2012 15:25:48 +0000"
    }
}

以及查询,在代码中和在 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}})

分别是 2012 年 12 月 13 日星期四 09:30:00 GMT2012 年 12 月 13 日星期四 16:00:00 GMT

应该说,给我所有的推文gte this intlte this other int。然而,它返回一切——它似乎根本没有限制这些值。

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

另外,我的理解是带有参数列表的 find(...) 是一个隐含的 AND。

太棒了!

【问题讨论】:

    标签: python mongodb datetime pymongo epoch


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-09-21
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      • 2015-12-27
      • 1970-01-01
      • 2015-08-09
      相关资源
      最近更新 更多