Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
total.rb
require 'mongo'
class total
def initialize
db = URI.parse(ENV['MONGOHQ_URL'])
db_name = db.path.gsub(/^\//, '')
@mongo = Mongo::Connection.new(db.host, db.port).db(db_name)
@mongo.authenticate(db.user, db.password) unless (db.user.nil? || db.user.nil?)
end
def add(user, collection_name)
coll = @mongo.collection(collection_name)
doc = {'school_id' => user.class.school_id, 'class_id' => user.class_id, 'date' => Time.now}
coll.insert(doc)
end
def count_class(user, collection_name, from_date , to_date)
coll = @mongo.collection(collection_name)
coll.count('class_id' => user.class_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment