Reputation: 332
I am fairly new to Ruby and MongoDB in particular. I use Mongo in a Ruby script to store and process thousands of Tweets in a collection. I would love to improve legibility and "rubyness" of the find command here:
require 'rubygems'
require 'mongo'
db = Mongo::Connection.new("localhost").db("db")
coll = db.collection("tweets")
cursor = coll.find({
'geo_enabled' => true,
'status.text' => { '$exists' => true },
'followers_count' => {
'$gte' => 10,
'$lt' => 100 }
})
cursor.each_with_index { |row,idx|
# do stuff
}
The mongodb query syntax drives me nuts! Is there a more elegant, ruby-like way to do a query?
Upvotes: 0
Views: 1549
Reputation: 1806
You can use Mongoid, it has nice syntax for queries, much similar to that of ActiveRecord/ActiveRelation.
Upvotes: 2