-
Type: Bug
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: 6.4.8
-
Component/s: Persistence
-
None
The use runtime persistence options causes the following error when trying to update a document:
The option database cannot be set on a new collection instance. The options that can be updated are [:read, :read_concern, :write, :write_concern] (Mongo::Error::UnchangeableCollectionOption)
Here is a snippet to reproduce the error:
require 'mongoid' Mongoid.configure do |config| config.connect_to('main') end class User include Mongoid::Document field:name, type: String end user = User.new(name: 'John') user.with(database: 'alt') do |u| u.save! end # 1st try: reusing the same user object user.with(database: 'alt') do |u| u.update(name:'John Doe 2') # raises Mongo::Error::UnchangeableCollectionOption end # 2nd try: using a new user object User.with(database: 'alt') do |clazz| u=clazz.find_by(name:'John') u.update(name:'John Doe 1') # raises Mongo::Error::UnchangeableCollectionOption end
The 1st try uses the code suggested in the documentation: https://www.mongodb.com/docs/mongoid/6.4/tutorials/mongoid-persistence/#runtime-persistence-options
- duplicates
-
MONGOID-5379 The use runtime persistence raises an error for updates
- Closed