Sha256: d02bc8aebf02f08e3759d721ccf93f9e27bf2c9ef169f327001ed4b9294e31ab

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

require_relative 'szmq/szmq'
require 'json'
require 'mongo'

module Kymera

  class MongoDriver
    include Mongo


    def self.log_results(log, address = "localhost", port = 27017, database = 'default_db', collection = 'default_collection')
      puts "Sending results to mongodb..."
      MongoDriver.new(address, port, database, collection).write_log(log)
    end


    #This can be initialized by specifying the address and the port of the mongodb server. By default, this expects that the
    #mongodb server is located on the same machine as the calling code. A collection name will also be defaulted if not passed in.
    #By default, this will be 'default_db'
    def initialize(address = "localhost", port = 27017, database = 'default_db', collection = 'default_db')
      puts "Initializing db connection.."
      @db_client = MongoClient.new(address, port).db(database)
      puts "Assigning collection..."
      @collection = collection
    end


    #The @param log needs to be a JSON string.
    def write_log(log)
      puts "Getting collection..."
      coll = @db_client["#{@collection}"]
      puts "Sending insert request.."
      coll.insert(JSON.parse log)
      puts "Request completed"
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
kymera-0.1.7 lib/kymera/mongo_driver.rb
kymera-0.1.6 lib/kymera/mongo_driver.rb
kymera-0.1.5 lib/kymera/mongo_driver.rb
kymera-0.1.4 lib/kymera/mongo_driver.rb
kymera-0.1.3 lib/kymera/mongo_driver.rb
kymera-0.1.2 lib/kymera/mongo_driver.rb
kymera-0.1.1 lib/kymera/mongo_driver.rb
kymera-0.1.0 lib/kymera/mongo_driver.rb