lib/mongodb_logger/adapters/moped.rb in mongodb_logger-0.6.3 vs lib/mongodb_logger/adapters/moped.rb in mongodb_logger-0.6.4

- old
+ new

@@ -24,11 +24,11 @@ def create_collection @connection.command(create: collection_name, capped: true, size: @configuration[:capsize].to_i) end def insert_log_record(record, options = {}) - record[:_id] = ::BSON::ObjectId.new + record[:_id] = bson_object_id.new @connection.with(write: options[:write_options])[collection_name].insert(record) end def collection_stats collection_stats_hash(@connection.command(collStats: collection_name)) @@ -44,11 +44,11 @@ def filter_by_conditions(filter) @collection.find(filter.get_mongo_conditions).limit(filter.get_mongo_limit).sort('$natural' => -1) end def find_by_id(id) - @collection.find("_id" => ::BSON::ObjectId.from_string(id)).first + @collection.find("_id" => bson_object_id.from_string(id)).first end def calculate_mapreduce(map, reduce, params = {}) @connection.command( mapreduce: collection_name, @@ -71,9 +71,13 @@ else conn = ::Moped::Session.new(["#{@configuration[:host]}:#{@configuration[:port]}"], timeout: 6, ssl: @configuration[:ssl]) end @connection_type = conn.class conn + end + + def bson_object_id + defined?(::BSON::ObjectId) ? ::BSON::ObjectId : ::Moped::BSON::ObjectId end end end end \ No newline at end of file