2012-11-12 77 views
0

我已經通過Streaming API收集了推文,並且想從MongoDB中進行查詢。MongoDB和Twitter查詢

我是新來的MongoDB,所以這會是正確的語法來查詢與任何座標或位置信息的tweet:

cursor = coll.find({"coordinates.type" : "Point"},{"coordinates" :1} or {"location": not "null" }, tailable = True, timeout = False) 

我使用pymongo,這是一個上限的集合。

感謝

回答

3

看看兩個$或$ NE運營商。

從官方MongoDB的文檔:

$或http://docs.mongodb.org/manual/reference/operator/or/

的$或操作員執行的兩個或 多個陣列中的邏輯或運算,並選擇滿足在文件至少有一個 的。

$ NEhttp://docs.mongodb.org/manual/reference/operator/ne/

$ NE選擇的文件,其中該字段的值不等於 (即=!)爲指定的值。這包括不包含 包含該字段的文檔。

你需要重寫查詢如下:

cursor = coll.find({ $or : [{"coordinates.type" : "Point"},{"location": {$ne :"null" }}]},{"coordinates" :1}, tailable = True, timeout = False) 
+0

謝謝,但它不應該是:光標= coll.find({$或:[{ 「coordinates.type」:「點「},{」coordinates「:1}]},{」location「:{$ ne:」null「}},tailable = True,timeout = False) – user94628

+0

find()函數的第一個參數是條件,第二個引用你想要檢索的字段的子集(在你的情況下,「座標」)。 – epochiero

+0

好吧,所以coordinates.type和location是條件,座標將成爲coordinate.type的一個子集。 – user94628