In this bankruptcy, we will cover the FROM clause, which goes nothing like a trendy FROM clause in ordinary SQL.
Queries continually run in the context of a specific series and can't be a part of throughout documents inside the collection, which makes us wonder why we need a FROM clause. In reality, we don't, but if we don't include it, then we might not be querying files within the series.
The purpose of this clause is to specify the records supply upon which the question ought to function. Commonly the whole series is the source, but you'll specify a subset of the collection as a substitute. The FROM <from_specification> clause is non-obligatory unless the supply is filtered or projected later within the query.
Let’s take a look at the same instance once more. Following is the AndersenFamily file.
{
"id": "SmithFamily",
"parents": [
{ "familyName": "Smith", "givenName": "James" },
{ "familyName": "Curtis", "givenName": "Helen" }
],
"children": [
{
"givenName": "Michelle",
"gender": "female",
"grade": 1
},
{
"givenName": "John",
"gender": "male",
"grade": 7,
"pets": [
{ "givenName": "Tweetie", "type": "Bird" }
]
}
],
"location": {
"state": "NY",
"county": "Queens",
"city": "Forest Hills"
},
"isRegistered": true
}
Following is the SmithFamily report.
{
"id": "WakefieldFamily",
"parents": [
{ "familyName": "Wakefield", "givenName": "Robin" },
{ "familyName": "Miller", "givenName": "Ben" }
],
"children": [
{
"familyName": "Merriam",
"givenName": "Jesse",
"gender": "female",
"grade": 6,
"pets": [
{ "givenName": "Charlie Brown", "type": "Dog" },
{ "givenName": "Tiger", "type": "Cat" },
{ "givenName": "Princess", "type": "Cat" }
]
},
{
"familyName": "Miller",
"givenName": "Lisa",
"gender": "female",
"grade": 3,
"pets": [
{ "givenName": "Jake", "type": "Snake" }
]
}
],
"location": { "state": "NY", "county": "Manhattan", "city": "NY" },
"isRegistered": false
}
In the above question, “SELECT * FROM c” suggests that the entire Families series is the source over which to enumerate.
Sub-documents
The supply also can be decreased to a smaller subset. When we need to retrieve handiest a subtree in every record, the sub-root should then come to be the supply, as shown within the following example.
When we run the subsequent question −
SELECT * FROM Families.parents
The following sub-files can be retrieved.
[
[
{
"familyName": "Wakefield",
"givenName": "Robin"
},
{
"familyName": "Miller",
"givenName": "Ben"
}
],
[
{
"familyName": "Smith",
"givenName": "James"
},
{
"familyName": "Curtis",
"givenName": "Helen"
}
],
[
{
"firstName": "Thomas",
"relationship": "father"
},
{
"firstName": "Mary Kay",
"relationship": "mother"
}
]
]
As a end result of this query, we can see that simplest the dad and mom sub-documents are retrieved.