Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

json - Cosmos DB documents result in an array

Suppose I am querying Cosmos DB with the following query (SELECT c.Name, c.Job FROM C) an having the following 2 documents as a result:

[{
"Name":"test",
"Job" : "Hello"
},
{
"Name":"test2",
"Job" : "Hello2"
}]

I would like to have the results in a array for every attribute like following:

[{
"Name" : ["test", "test2"],
"Job" : ["Hello", "Hello2"]
}]

I would like to know if this is possible in cosmos db and if anyone has experience with this. I would appreciate it!

Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's impossible to get your expected output with one SQL in Cosmos DB. You need to make two call:

SELECT 
    value c.Name
FROM c

AND

SELECT 
    value c.Job
FROM c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...