How to retrieve nested properties along with the id from Azure DocumentDB -


i have documents stored in documentdb follow basic design:

{   "id": "abc123",   "hiddenfield": "xxxxxx",   "attributes": {     "x": "7",     "y": "8",     "z": "9"   } } 

in example there 3 properties under attributes, not constant in practice. want retrieve without hidden field , project arbitrary number of attributes root of document alongside id:

{   "id": "abc123",   "x": "7",   "y": "8",   "z": "9" } 

with query can x, y, , z root:

select value c.attributes c 

which produce result:

{   "x": "7",   "y": "8",   "z": "9" } 

...but query invalid:

select c.id, value c.attributes c 

which understandable docs can either list properties or use value operator. fair enough.

is there way use join operator or other projection end desired result set?

based on scenario, assumed refer following query:

select     c.id,     c.attributes.x x,     c.attributes.y y,     c.attributes.z z yourinput c 

sample data:

[{   "id": "abc123",   "hiddenfield": "xxxxxx",   "attributes": {     "x": "7",     "y": "8",     "z": "9"   } },{   "id": "abc456",   "hiddenfield": "xxxxxx",   "attributes": {     "x": "1",     "y": "2",     "z": "3"   } }] 

result:

enter image description here

update:

since number of attributes property in document arbitrary, assumed leverage user defined functions (udfs) achieve purpose follows:

udf.fun

function main(attributes, id) {     attributes["id"]=id;     //add other properties here     return attributes; } 

query:

select     udf.fun(attributes,id)     [yourinputalias] 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -