diff --git a/language_specification/projection.md b/language_specification/projection.md index c4afcf8..1287127 100644 --- a/language_specification/projection.md +++ b/language_specification/projection.md @@ -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": , "include": boolean, recursive: boolean } -array_projection := { "field": , "include": boolean, - match: query_expression, project : projection, sort : sort } } | - { "field": , "include": boolean, - "range": [ from, to ], project : projection, "sort": sort } +field_projection := { "field": , "include": boolean[true], "recursive": boolean[false] } +array_projection := { "field": , "include": boolean[true], + match: query_expression, projection : projection, sort : sort } } | + { "field": , "include": boolean[true], + "range": [ from, to ], projection : projection, "sort": sort } ``` Examples: @@ -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 @@ -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. \ No newline at end of file diff --git a/language_specification/update.md b/language_specification/update.md index 739dd73..62f367a 100644 --- a/language_specification/update.md +++ b/language_specification/update.md @@ -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": , "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 ``` @@ -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 } } @@ -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 @@ -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`.