DocumentDB查找深键:值 [英] DocumentDB find deep key:value
问题描述
在MongoDB中,我可以在任何深层键上进行查找,例如
in MongoDB I can perform a find on any deep level key like
collection.find('persons.age': 12)
文档DB可能有类似的事情吗?我已经尝试过类似以下的操作,但失败了:代码:" BadRequest-无法解决.
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"
推荐答案
您必须引用FROM
子句中的集合.
You must reference the collection from the FROM
clause.
注意:由于您是直接向集合发出查询,因此可以使用任意值作为名称.但是,您必须重新使用在其他子句中选择的任何值,因为它用作预测和谓词的参考点(在SELECT和WHERE子句中).
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
这篇关于DocumentDB查找深键:值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!