0
votes

when running below query it's returning records from collection:

SELECT * 
FROM Families f 
WHERE f.id = "AndersenFamily"

I tried in C# also and got same results:

query = client.CreateDocumentQuery<Family>(collectionLink, new SqlQuerySpec
            {
                QueryText = "SELECT * FROM Families f WHERE (f.id = @name)",
                Parameters = new SqlParameterCollection()  {
                          new SqlParameter("@name", "AndersenFamily")
                     }
            });

What's the significance of "Families"? ASFAIK it's not db name, collection name ,or any document name then why it's returning results?

I also tried to replace "Families" with some different word and I still got the results.

You can see the code here https://docs.microsoft.com/en-us/azure/documentdb/documentdb-sql-query

1
Are you seeing that when running the query from C#, or only in the Playground? If it's in the playground, it's probably a playground-specific aspect and unrelated to C#. (I strongly suspect this has nothing to do with C# or .NET either way, to be honest.) - Jon Skeet
@Skeet it's in C# code. I've updated the question. - GorvGoyl
Hmm. Given the behaviour in the playground, I still think this is really just a DocumentDb question, and knowledge of .NET and C# is irrelevant. The documentation isn't terribly clear to be honest - although it does say that the FROM clause is optional in most cases. - Jon Skeet

1 Answers

1
votes

DocumentDB supports querying using SQL syntax but since it actually is a NoSQL storage, the concept of tables does not exist.

When structuring a SQL query on DocumentDB, the FROM clause (which is optional) specifies the source which can contain the collection name and an alias.

In the case of your example, Families is acting as the collection name and f is acting as an alias. If you are creating a query against a single collection (which is the most common case), you don't really need to specify the collection name, you can simply use a reference to the collection contents (documents) like so:

SELECT * FROM f WHERE f.id = "AndersenFamily"

My opinion is that the Families reference is made so folks coming from a SQL scenario can relate to the query structure (looks like referencing a table).