带有JOIN的DocumentDb SELECT不返回任何内容 [英] DocumentDb SELECT with JOIN not returning anything
问题描述
我在DocumentDb中的文档如下:
My document in DocumentDb looks like this:
{
"id": 123,
"timers":
{
"projectTimer":
{
"id": 234,
"name": "My Project",
"startTime": "10:35 AM"
},
"taskTimer":
{
"id": 789,
"name": "My Task",
"startTime": "10:45 AM"
}
}
}
这里的关键点是:
- 计时器"是一个对象-不是数组
- 还设置了子对象,即"projectTimer"和"taskTimer"
如果我将SELECT语句设置为以下内容,则可以通过给我同时提供projectTimer和taskTimer子对象来实现
If I set my SELECT statement to the following, it works by giving me both projectTimer and taskTimer sub-objects
SELECT c.timers
FROM Collection c
WHERE c.id = 123
但是以下内容不返回任何内容.我不明白为什么,因为它看起来像是一个非常简单的JOIN:
But the following returns nothing. I don't understand why because it seems like a really simple JOIN:
SELECT t.projectTimer
FROM Collection c
JOIN t IN c.timers
WHERE c.id = 123
知道我在哪里犯错吗?
推荐答案
问题是您正在尝试对非数组对象执行 JOIN
.
The issue is that you're trying to do a JOIN
on something that's not an array.
相反,如果您稍微修改了文档,则:
If, instead, you reworked your document slightly:
{
"id": "123",
"timers": [
{
"projectTimer": {
"id": 234,
"name": "My Project",
"startTime": "10:35 AM"
}
},
{
"taskTimer": {
"id": 789,
"name": "My Task",
"startTime": "10:45 AM"
}
}
],
}
然后您就可以执行 JOIN
,例如:
You'd then be able to do a JOIN
like:
select value t
from collection c
join t in c.timers
where c.id = "123"
哪个会返回数组中的每个计时器:
Which would return each of the timers in the array:
[
{
"projectTimer": {
"id": 234,
"name": "My Project",
"startTime": "10:35 AM"
}
},
{
"taskTimer": {
"id": 789,
"name": "My Task",
"startTime": "10:45 AM"
}
}
]
请注意在查询中使用 VALUE
,以除去包含的 t
变量.
Note the use of VALUE
in the query, to strip away the containing t
variable.
这篇关于带有JOIN的DocumentDb SELECT不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!