How to use SQL Query with hyphen in Collection name?

前端 未结 1 1097
猫巷女王i
猫巷女王i 2021-01-20 06:11

Does anyone know how to use a SQL query on a CosmosDB Collection that has a hyphen in the name? For example

SELECT * FROM product-group where product-group.i         


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 06:41

    When you query via DocumentDB SQL, you don't need to specify the exact collection name; you're really specifying an alias in your query.

    In the Query Explorer (via the portal), all queries are done by first selecting a collection. At that point, use a simple alias to query. For example, here is a query against a collection called sample-data (as selected in the "Collections" dropdown), but I don't need to specify the actual collection name in the query. I simply use mycollection as an alias for sample-data:

    And in code, the SDK call includes both a database parameter and a collection parameter, again obviating the need for the actual collection name in the query. For example, the same query, called from c#, might look something like this:

    client.CreateDocumentQuery(
                UriFactory.CreateDocumentCollectionUri("mydb", "sample-data"),
                "SELECT * FROM mycollection WHERE mycollection.id = '3829503'");
    

    0 讨论(0)
提交回复
热议问题