-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 4.0.0 final
-
Component/s: None
-
None
I have some very large documents. Due to embedados and arrays fields.
An example follows:
{"_id" => BSON :: ObjectId ('5654b4b3204528cfa0000001'),
"rating" => 1,
"status" =>: ok,
"bound_count" => 5,
"group_ids" =>
[BSON :: ObjectId ('55ba5d5420452896a8000007'),
BSON :: ObjectId ('5602bf4c2045289107000001')]
"events": [
{"_id" => BSON :: ObjectId ('5654b4b3204528cfa0000002'),
"field_a" =>: died,
"field_b" => {},
"EVENT_DATE" => 11.24.2015 19:04:19 UTC
"trigger" => true,
'type' =>: INLIST,
"list_id" => BSON :: ObjectId ('5602bf4c2045289107000001'),
"updated_at" => 11.24.2015 19:04:19 UTC
"created_at" => 11.24.2015 19:04:19 UTC}
]}
There may be hundreds of events and no more than ten group_ids for example.
For my application I need some fields, but do not need the events.
In version 3 Mongoid I filtered the necessary fields, performing my actions and alter some of these fields returned.
entry = Model.without (: events) .first
- Logic of my application
entry.rating = 3
entry.status = :error
entry.save - raise Mongoid::Errors::ReadonlyDocument
But Mongoid 4: "Documents now loaded from criteria using #only or #without will now raise an error When Attempting to save".
I can not work it out with atomic operations. Because my model has callbacks (after_save, before_update) that depend on previous states of fields (ActiveModel :: Dirty).
They can help me with any suggestions?
- duplicates
-
MONGOID-3535 Using mongoid 'only' or 'without' creates read-only objects
- Closed