class Connector::MongoConnector
Defines MongoDB connection properties¶ ↑
Attributes
client[RW]
coll[RW]
coll_name[RW]
db_name[RW]
host[RW]
port[RW]
Public Class Methods
new(coll_name, db_name: 'ccsdm', host: 'localhost', port: '27017')
click to toggle source
# File lib/mylookup/connector.rb, line 11 def initialize(coll_name, db_name: 'ccsdm', host: 'localhost', port: '27017') @coll_name, @db_name, @host, @port = coll_name, db_name, host, port Mongo::Logger.logger.level = Logger::WARN @conn_str = @host + ':' + @port @client = Mongo::Client.new([@conn_str], :database => @db_name) @coll = @client[@coll_name] end
Public Instance Methods
collection_exists?()
click to toggle source
# File lib/mylookup/connector.rb, line 24 def collection_exists? recs({}) > 0 end
field_exists?(field)
click to toggle source
# File lib/mylookup/connector.rb, line 28 def field_exists? field @coll.find({}).projection({ '_id' => 0 }).limit(1).collect { |doc| doc }[0].keys.include? field end
recs(qry)
click to toggle source
Queries and returns number of documents in the collection
# File lib/mylookup/connector.rb, line 20 def recs qry @coll.find(qry).count end