MongoDB和Twitter查询

问题描述:

我已经通过Streaming API收集了推文,并且想从MongoDB中进行查询。MongoDB和Twitter查询

我是新来的MongoDB,所以这会是正确的语法来查询与任何坐标或位置信息的tweet:

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

我使用pymongo,这是一个上限的集合。

感谢

看看两个$或$ 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