2012-12-17 43 views
1

我試圖從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}}) 

哪些是週四,二零一二年十二月一十三日09:30: 00 GMT and 2012年12月13日星期四16:00:00 GMT

應該說,讓我所有的鳴叫GTE這個中斷LTE這個其他INT。然而,它會返回一切 - 它似乎並沒有限制這些值。

例如,該條目返回,並且時間戳:是:星期三,2012年12月12日15時25分48秒GMT

而且,我的理解是找到(... )與params列表是一個隱含的AND。

TIA SO!

回答

5

您的查詢對象中不能有兩個同名的鍵。您必須將它們合併爲一個像這樣的單個值:

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

啊,謝謝!作品。我是一個python/mongo noob。 –

相關問題