Mongoid fails to reload documents with sharded fields that have been modified. The simple repro below uses Mongoid's Profile test model to exhibit this behavior.
Repro: (create, modify shard key, save, reload, BROKEN)
let(:profile) do # Profile shard_key :name Profile.create(name: "Alice") end it "successfully reloads the document after saving an update to the sharded field" do expect(profile.name).to eq("Alice") profile.name = "Bob" profile.save() # Fails profile.reload() expect(profile.name).to eq("Bob") end
The line marked as # Fails above fails with the following error:
Failure/Error: raise Errors::DocumentNotFound.new(self.class, _id, _id) Mongoid::Errors::DocumentNotFound: message: Document(s) not found for class Profile with id(s) 606fabb4235bf0215ae36b7f. summary: When calling Profile.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. The search was for the id(s): 606fabb4235bf0215ae36b7f (1 total) and the following ids were not found: 606fabb4235bf0215ae36b7f. resolution: Search for an id that is in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error when searching for a single id, or only the matched documents when searching for multiples.
The failure occurs because atomic_selector at the time of the call is set to:
{{"_id"=>BSON::ObjectId('606fabb4235bf0215ae36b7f'), "name"=>"Alice"}}
- is related to
-
MONGOID-5078 Background jobs queued during after_save, which atomically query sharded documents, fail because of atomic_selector.
- Closed
-
MONGOID-5077 DocumentNotFound message fails to account for shard key
- Closed
- links to