The manual mentions aggregation expressions everywhere. For example, the “$set” aggregation operator has the following syntax:
{ $set: { <newField>: <expression>, ... } }
But the link to “aggregation expression” in its documentation simply points to the aggregation operators page. From what I can tell from the examples, you can also use $set with values from the document using a field path (e.g. $field).
- Where can I find in the documentation what an aggregation expression can be? Can it be anything else other than an operator or a field path?
Next, the field path is defined like so:
Path to a field in a document. To specify a field path, use a string that prefixes the field name with a dollar sign (
$).
And the docs say this about it:
To specify a field path, prefix the field name or the dotted field name (if the field is in the embedded document) with a dollar sign
$.
The linked dot notation documentation contains the following:
To specify or access an element of an array by the zero-based index position, concatenate the array name with the dot (
.) and zero-based index position, and enclose in quotes:"<array>.<index>"
This works great with a query:
{ "myArray.0.someField": 123 }
However, the corresponding field path "$myArray.0.someField" evaluates to an empty array. For example, running the $set query with { test: "$myArray.0.someField" } will produce documents with the test field being an empty array, every time.
- Where can I find documentation about this? Does the field path not support dot notation fully? Or is this a limitation of the
$setoperator?