lib/pupa/processor/connection_adapters/mongodb_adapter.rb in pupa-0.1.11 vs lib/pupa/processor/connection_adapters/mongodb_adapter.rb in pupa-0.2.0

- old
+ new

@@ -1,6 +1,6 @@ -require 'moped' +require 'mongo' module Pupa class Processor class Connection # A proxy class to save plain old Ruby objects to MongoDB. @@ -8,11 +8,11 @@ attr_reader :raw_connection # @param [String] database_url the database URL def initialize(database_url) uri = URI.parse(database_url) - @raw_connection = Moped::Session.new(["#{uri.host}:#{uri.port}"], database: uri.path[1..-1]) + @raw_connection = Mongo::Client.new(["#{uri.host}:#{uri.port}"], database: uri.path[1..-1]) @raw_connection.login(uri.user, uri.password) if uri.user && uri.password end # Finds a document matching the selection criteria. # @@ -58,19 +58,19 @@ # Run query before callbacks to avoid e.g. timestamps in the selector. case query.count when 0 object.run_callbacks(:save) do object.run_callbacks(:create) do - collection.insert(object.to_h(persist: true)) + collection.insert_one(object.to_h(persist: true)) [true, object._id.to_s] end end when 1 # Make the document available to the callbacks. - # @see https://github.com/opennorth/pupa-ruby/issues/17 + # @see https://github.com/jpmckinney/pupa-ruby/issues/17 object.document = query.first object.run_callbacks(:save) do - query.update(object.to_h(persist: true).except(:_id)) + query.update_one(object.to_h(persist: true).except(:_id)) [false, object.document['_id'].to_s] end else raise Errors::TooManyMatches, "selector matches multiple documents during save in collection #{collection_name} for #{object._id}: #{JSON.dump(selector)}" end