我有一个Rails应用程序,我需要为其中一个服务器一直启用MongoDB的安全模式。
如何为所有请求启用安全模式?
答案 0 :(得分:2)
http://api.mongodb.org/ruby/current/file.WRITE_CONCERN.html
@con = Mongo::Connection.new('localhost', 27017, :safe => {:w => 2})
@db = @con['test']
@collection = @db['foo']
@collection.save({:name => 'foo'})
@collection.save({:name => 'bar'}, :safe => false)