Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The 'safe' write concern option has been deprecated in favor of 'w' #507

Closed
xjia1 opened this issue Apr 3, 2013 · 5 comments
Closed

The 'safe' write concern option has been deprecated in favor of 'w' #507

xjia1 opened this issue Apr 3, 2013 · 5 comments

Comments

@xjia1
Copy link

xjia1 commented Apr 3, 2013

I'm running the code below and got a warning message:

[DEPRECATED] The 'safe' write concern option has been deprecated in favor of 'w'.

Google gives something related: http://www.manning-sandbox.com/thread.jspa?messageID=135496&tstart=0

require 'mongo_mapper'

ENV['MONGODB_URI'] = 'mongodb://localhost/test'
MongoMapper.setup({'production' => {'uri' => ENV['MONGODB_URI']}}, 'production')

class User
  include MongoMapper::Document

  key :name, String
  key :age, Integer

  many :hobbies
end

class Hobby
  include MongoMapper::EmbeddedDocument

  key :name, String
  key :started, Time
end

user = User.new(:name => 'Brandon')
user.hobbies.build(:name => 'Programming', :started => 10.years.ago)
user.save!
User.where(:name => 'Brandon').first
@brndnblck
Copy link

The deprecation notice is actually coming from the mongo-ruby-driver one level below:
https://github.com/mongodb/mongo-ruby-driver/blob/1.8.4/lib/mongo/util/write_concern.rb#L10

In short:

# deprecated syntax, triggers warning
collection.save doc, :safe => true
# new syntax for "safe" mode
collection.save doc, :w => 1

You can read more about the deprecation of "safe" here:
http://blog.mongodb.org/post/36666163412/introducing-mongoclient

You can read more about MongoDB's write concerns here:
http://docs.mongodb.org/manual/core/write-operations/#write-concern

@szymon-jez
Copy link

@stfairy Here is a quick and dirty monkey patch:

# Monkey Patch to solve issue https://github.com/jnunemaker/mongomapper/issues/507
module MongoMapper
  module Plugins
    module Querying
      private
        def save_to_collection(options={})
          @_new = false
          collection.save(to_mongo, :w => options[:safe] ? 1 : 0)
        end
    end
  end
end

I wonder, why is this not already fixed?

@shevaun
Copy link
Contributor

shevaun commented May 28, 2013

+1

@theirishpenguin
Copy link

FYI, the master has this fixed (though not the latest gem).

@jnunemaker
Copy link
Contributor

This is fixed in master. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants