【问题标题】:MongoDB and Twitter queryMongoDB 和 Twitter 查询
【发布时间】:2012-11-01 10:23:27
【问题描述】:

我已通过 Streaming API 收集推文,并希望从 mongodb 进行查询。

我是 MongoDB 的新手,所以这是用坐标或位置信息查询推文的正确语法:

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

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

谢谢

【问题讨论】:

    标签: python mongodb twitter tweepy


    【解决方案1】:

    看看 $or$ne 运算符。

    来自 MongoDB 官方文档:

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

    $or 运算符对包含两个或的数组执行逻辑或运算 more 并选择至少满足一个的文档 的。

    $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)
    

    【讨论】:

    • 谢谢,但不应该是:cursor = coll.find({ $or : [{"coordinates.type" : "Point"},{"coordinates": 1}]}, {"location" : {$ne: "null"}}, tailable = True, timeout = False)
    • find() 函数的第一个参数是条件,第二个参数是您要检索的字段子集(在您的情况下为“坐标”)。
    • 好的,coordinates.type 和 location 是条件,coordinates 将是coordinates.type 的子集
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多