Class Miscellaneous
java.lang.Object
dev.morphia.aggregation.expressions.Miscellaneous
Defines miscellaneous operators for aggregations.
- Since:
- 2.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic GetFieldExpression
Returns the value of a specified field from a document.static GetFieldExpression
Returns the value of a specified field from a document.static Expression
rand()
Returns a random float between 0 and 1.static Filter
sampleRate
(double rate) Matches a random selection of input documents.static Expression
Adds, updates, or removes a specified field in a document.static Expression
unsetField
(Object field, Object input) Removes a specified field in a document.
-
Method Details
-
getField
Returns the value of a specified field from a document. If you don't specify an object, $getField returns the value of the field from $$CURRENT.- Parameters:
field
- the field name- Returns:
- the new expression
- Since:
- 2.3
- MongoDB documentation
- Aggregration Expression: $getField
- Since server release
- 5.0
-
getField
Returns the value of a specified field from a document. If you don't specify an object, $getField returns the value of the field from $$CURRENT.- Parameters:
field
- the expression yielding the field name- Returns:
- the new expression
- Since:
- 2.3
- MongoDB documentation
- Aggregration Expression: $getField
- Since server release
- 5.0
-
rand
Returns a random float between 0 and 1.- Returns:
- the filter
- Since:
- 2.2
- MongoDB documentation
- Aggregration Expression: $rand
- Since server release
- 4.4.2
-
sampleRate
Matches a random selection of input documents. The number of documents selected approximates the sample rate expressed as a percentage of the total number of documents.- Parameters:
rate
- the rate to check against- Returns:
- the filter
- Since:
- 2.2
- MongoDB documentation
- Aggregration Expression: $sampleRate
- Since server release
- 4.4.2
-
setField
Adds, updates, or removes a specified field in a document.- Parameters:
field
- Field in the input object that you want to add, update, or remove. field can be any valid expression that resolves to a string constant.input
- Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined.value
- The value that you want to assign to field. value can be any valid expression. Set to $$REMOVE to remove field from the input document.- Returns:
- the new expression
- Since:
- 2.3
- MongoDB documentation
- Aggregration Expression: $setField
- Since server release
- 5.0
-
unsetField
Removes a specified field in a document.- Parameters:
field
- the expression yielding the field nameinput
- Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined.- Returns:
- the new expression
- Since:
- 2.3
- MongoDB documentation
- Aggregration Expression: $unsetField
- Since server release
- 5.0
-