Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions language_specification/projection.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ the field remains excluded, and vice versa.
projection := basic_projection | [ basic_projection, ... ]
basic_projection := field_projection | array_projection

field_projection := { "field": <pattern>, "include": boolean, recursive: boolean }
array_projection := { "field": <pattern>, "include": boolean,
match: query_expression, project : projection, sort : sort } } |
{ "field": <pattern>, "include": boolean,
"range": [ from, to ], project : projection, "sort": sort }
field_projection := { "field": <pattern>, "include": boolean[true], "recursive": boolean[false] }
array_projection := { "field": <pattern>, "include": boolean[true],
match: query_expression, projection : projection, sort : sort } } |
{ "field": <pattern>, "include": boolean[true],
"range": [ from, to ], projection : projection, "sort": sort }
```
Examples:

Expand All @@ -35,13 +35,13 @@ Return everything but firstname:
Return only those elements of the addresses array with
city="Raleigh", and only return the streetaddress field.
```javascript
[ { "field": "address", "include": true,
"match": { "city": "Raleigh" }, "project": { "streetaddress": true} } ]
[ { "field": "addresses", "include": true,
"match": { "city": "Raleigh" }, "projection": { "field": "streetaddress"} } ]
```
Return the first 5 addresses
```javascript
[ { "field": "address", "include": true, "range": [ 0, 4 ],
"project": { "*", "recursive": true} }]
[ { "field": "addresses", "include": true, "range": [ 0, 4 ],
"projection": { "*", "recursive": true} }]
```

### Sorting array elements in projection
Expand All @@ -63,4 +63,4 @@ projects the array 'someArray', thus the elements are not sorted. Whereas:
[ { "field": "*", "include": true },
{ "field": "someArray", "include": true, "range": [0,2], "sort": {"someField":"$asc"} } ]
```
Here, both projection expression include "someArray", but the latest inclusion contains the sort, so the array elements are sorted.
Here, both projection expression include "someArray", but the latest inclusion contains the sort, so the array elements are sorted.
43 changes: 39 additions & 4 deletions language_specification/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@
```javascript
update_expression := partial_update_expression |
[ partial_update_expression,...]

partial_update_expression := primitive_update_expression |
array_update_expression

primitive_update_expression := { $set : { path : rvalue_expression , ...} } |
{ $set : { path : rvalue_expression }, fields : field_projection | [ field_projection, ... ]
{ $unset : path } |
{ $unset :[ path, ... ] }
{ $add : { path : rvalue_expression, ... } }

rvalue_expression := value | { $valueof : path }

value := primitive_value | json_container

field_projection := { "field": <pattern>, "include": boolean[true], "recursive": boolean[false] }

json_container := jsonObjectNode | jsonArrayNode

array_update_expression := { $append : { path : rvalue_expression } } |
{ $append : { path : [ rvalue_expression, ... ] }} |
{ $insert : { path : rvalue_expression } } |
{ $insert : { path : [ rvalue_expression,...] }} |
{ $foreach : { path : update_query_expression,
$update : foreach_update_expression } }
{ $foreach : { path : update_query_expression, $update : foreach_update_expression } }

update_query_expression := $all | query_expression

foreach_update_expression := $remove | update_expression
```

Expand All @@ -33,8 +42,10 @@ the first two elements of an array, use:
```javascript
{ "$set" : { "path" : value } }
{ "$set" : { "path" : [...] } }
{ "$set" : { "path" : { ... } } }
{ "$set" : { "path" : { "$valueof" : field } }
{ "$set" : { "path" : { ... } } }
{ "$set" : { "path" : { ... }, "fields" : [...] } }
{ "$set" : { "path" : { ... }, "fields" : { ... } } }
{ "$set" : { "path" : { "$valueof" : field } }
{ "$unset" : "path" } (array index is supported, can be used to
remove elements of array)
{ "$add" : { "path" : number } }
Expand Down Expand Up @@ -110,6 +121,13 @@ Remove x.y.z from doc.
```
$add is similar to $set

##### Examples of partial updates

```javascript
{ "$set": { "$this" : { "f1" : "foo", "f2" : "bar" } } , "fields" : { "field" : "f2" } }
```
Update an object with the given data, but only update field `f2`.

#### Examples of $foreach

```javascript
Expand Down Expand Up @@ -166,3 +184,20 @@ Set field 'k' in matching elements to 'blah' (".k" means
```
For each element of ```x.y.*.z``` where ```x.y.*.z.arr.p=1``` set ```x.y.*.z.arr.v```
to the value of ```k``` (k is from root of doc) .

##### Examples of partial updates

```javascript
"$foreach" : {
"x.y.z" : {
"field" : "f3", " op": "$eq", "value" = "jaber"
},
"$update" : {
"$set": {
"$this" : { "f1" : "foo", "f2" : "bar", "f3" : "jaber" }
},
"fields" : { "field" : "f2" }
}
}
```
`x` is an object, `y` is an object, `z` is an array. Update all objects in array `z` where `z` has a field `f3` that equals `jaber`, but only update field `f2` and set it to `bar`.