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
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'");