user94628
user94628

Reputation: 3721

MongoDB and Twitter query

I've collected tweet via the Streaming API and would like to make queries from the mongodb.

I'm new to MongoDB, so would this be the correct syntax to query for tweets with either coordinates or location information:

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

I'm using pymongo and this is a capped collection.

Thanks

Upvotes: 0

Views: 849

Answers (1)

epochiero
epochiero

Reputation: 81

Take a look at both the $or and $ne operators.

From the official MongoDB docs:

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

The $or operator performs a logical OR operation on an array of two or more and selects the documents that satisfy at least one of the .

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

$ne selects the documents where the value of the field is not equal (i.e. !=) to the specified value. This includes documents that do not contain the field.

You need to rewrite your query as following:

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

Upvotes: 3

Related Questions