DocumentDB find deep key:value

你。 提交于 2019-12-25 03:32:47

问题


in MongoDB I can perform a find on any deep level key like

collection.find('persons.age': 12)

Is a similar thing possible with document DB? I have tried something like the following which fails with: code":"BadRequest" - could not be resolved.

query: "SELECT * FROM root WHERE person.age = 12"

回答1:


You must reference the collection from the FROM clause.

Note: Since you are issuing queries directly to a collection, you can use any arbitrary value for the name. However, you must re-use whatever value you chose in the other clauses because it serves as a reference point for projections and predicates (in the SELECT and WHERE clause).

If your document's schema resembles:

{
    person: {
        age: 39
    }
}

You can query documents by age using:

SELECT *
FROM root
WHERE root.person.age = 39

Or if your document's schema resembles:

{
    age: 39
}

You can query documents by age using:

SELECT *
FROM person
WHERE person.age = 39


来源:https://stackoverflow.com/questions/30098772/documentdb-find-deep-keyvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!