DocumentDB-集合内的WHERE子句 [英] DocumentDB - WHERE clause within collection

查看:50
本文介绍了DocumentDB-集合内的WHERE子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Microsoft的示例中获得一个像这样的示例文档:

Given a sample document like this one from the Microsoft examples:

{
  "id": "AndersenFamily",
  "lastName": "Andersen",
  "parents": [
     { "firstName": "Thomas" },
     { "firstName": "Mary Kay"}
  ],
  "children": [
     {
         "firstName": "Henriette Thaulow", 
         "gender": "female", 
         "grade": 5,
         "pets": [{ "givenName": "Fluffy" }]
     }
  ],
  "address": { "state": "WA", "county": "King", "city": "seattle" },
  "creationDate": 1431620472,
  "isRegistered": true
}

我们可以看到有一个包含文档数组的子集合children.

We can see that there is a sub-collection children containing an array of documents.

假设我想使用SELECT ... FROM ... WHERE ...类型的语法编写查询,那么我将如何编写查询来查找有任何女儿(有女"性别的孩子)的家庭?

Let's say I wanted to write a query using the SELECT ... FROM ... WHERE ... type syntax, how would I go about writing a query to find families with any daughters (any children with gender "female")

类似

SELECT c.id
FROM c
WHERE c.children.contains(  // I'm stuck!

我想知道我是否想念JOIN之类的东西,但是老实说我不确定从这里走到哪里,而且我在努力寻找某些对Google有用的东西,因为我不确定如何用词组我的搜索!

I'm wondering if I'm missing a JOIN or something but honestly I'm not sure where I go from here, and I'm struggling to find anything helpful in Google partially because I'm not sure how to phrase my search!

推荐答案

您需要JOIN关键字来展开子级,然后将过滤器应用于性别,如以下查询所示:

You need the JOIN keyword to unwind the children, then apply the filter on gender like the query below:

SELECT f.id
FROM family f
JOIN child IN f.children
WHERE child.gender = "female"

这篇关于DocumentDB-集合内的WHERE子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆