DocumentDB find deep key:value

2019-09-01 15:56发布

问题:

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