如何在集合名称中使用带连字符的SQL查询? [英] How to use SQL Query with hyphen in Collection name?

查看:77
本文介绍了如何在集合名称中使用带连字符的SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何在名称中带有连字符的CosmosDB集合上使用SQL查询吗?例如

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.

推荐答案

通过DocumentDB SQL查询时,无需指定确切的集合名称;您实际上是在查询中指定别名.

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.

在查询资源管理器中(通过门户),所有查询都是通过首先选择一个集合来完成的.此时,请使用简单的别名进行查询.例如,这是一个针对名为sample-data的集合的查询(在集合"下拉列表中选择),但是我不需要在查询中指定实际的集合名称.我只是使用mycollection作为sample-data的别名:

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:

在代码中,SDK调用同时包含数据库参数和集合参数,从而再次消除了查询中对实际集合名称的需求.例如,从c#调用的同一查询可能看起来像这样:

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

这篇关于如何在集合名称中使用带连字符的SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆