pub enum Op {
Increment(f64),
Add(Vec<ParseValue>),
AddUnique(Vec<ParseValue>),
Remove(Vec<ParseValue>),
SetOnInsert(ParseValue),
Delete,
AddRelation(Vec<ParseValue>),
RemoveRelation(Vec<ParseValue>),
Batch(Vec<Op>),
}Expand description
A field operation.
Not #[non_exhaustive], for the reason given on ParseValue: a new operation must break
every write path that applies one, rather than falling into a wildcard arm that silently
ignores it.
Variants§
Increment(f64)
{"__op":"Increment","amount":n}. Negative amounts decrement; there is no separate op.
Add(Vec<ParseValue>)
{"__op":"Add","objects":[...]}. Appends, duplicates allowed.
AddUnique(Vec<ParseValue>)
{"__op":"AddUnique","objects":[...]}. Appends only values not already present.
Remove(Vec<ParseValue>)
{"__op":"Remove","objects":[...]}. Removes every occurrence.
SetOnInsert(ParseValue)
{"__op":"SetOnInsert","amount":v}. Sets the field only if the write inserts a row.
Note the key: amount, not objects and not value, and it carries an arbitrary value
rather than a number despite the name (MongoTransform.js:993-998). There is no type
check on it anywhere upstream, so there is none here.
Delete
{"__op":"Delete"}. Unsets the field.
AddRelation(Vec<ParseValue>)
{"__op":"AddRelation","objects":[pointers]}
RemoveRelation(Vec<ParseValue>)
{"__op":"RemoveRelation","objects":[pointers]}
Batch(Vec<Op>)
{"__op":"Batch","ops":[...]}. Upstream only ever produces a batch of relation ops, but
the decoder does not enforce that, so neither does this.
Implementations§
Source§impl Op
impl Op
Sourcepub fn classify(value: &Json) -> Result<Option<Op>, ParseError>
pub fn classify(value: &Json) -> Result<Option<Op>, ParseError>
Decode an {"__op":...} object on the update path.
Returns Ok(None) when the value is not an op at all, so a caller can try this before
falling back to crate::decode::classify without treating “not an op” as an error.
Sourcepub fn classify_with(
value: &Json,
path: OpPath,
) -> Result<Option<Op>, ParseError>
pub fn classify_with( value: &Json, path: OpPath, ) -> Result<Option<Op>, ParseError>
Decode an {"__op":...} object, with the path that decides one error message.
Sourcepub fn flatten_for_create(&self) -> Result<Option<ParseValue>, ParseError>
pub fn flatten_for_create(&self) -> Result<Option<ParseValue>, ParseError>
What this op collapses to on a create, per flattenUpdateOperatorsForCreate
(DatabaseController.js:323-365).
Ok(None) means the key is removed from the row entirely, which is what Delete does.
Two results are counter-intuitive and both are upstream’s: Remove yields an empty
array rather than removing anything, and the relation ops are not handled here at all
because collectRelationUpdates has already stripped them out.
Sourcepub fn echoes_result(&self) -> bool
pub fn echoes_result(&self) -> bool
Does the update response echo this op’s resulting value back to the client?
Exactly the five ops in _sanitizeDatabaseResult’s allow-list
(DatabaseController.js:2140). Delete is not one of them, which is why deleting a field
produces {updatedAt} and nothing else.