How to use SQL Query with hyphen in Collection name?

你离开我真会死。 提交于 2020-01-11 09:52:31

问题


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.id = "3829503"

I've see that properties can be accessed using the [""] syntax but haven't seen any solutions for the actual collection name.


回答1:


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<MyObject>(
            UriFactory.CreateDocumentCollectionUri("mydb", "sample-data"),
            "SELECT * FROM mycollection WHERE mycollection.id = '3829503'");


来源:https://stackoverflow.com/questions/46719930/how-to-use-sql-query-with-hyphen-in-collection-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!