如何从具有guid id的集合中选择? [英] how to select from collection with guid id?
问题描述
我有这个带有guid id的收藏.当我使用Azure Query Explorer并在上方的组合框中选择了集合时,就可以了:
I've got this collection with guid id. When i use Azure Query Explorer with collection selected in the combo box above it's ok:
SELECT * FROM c
但是当我尝试这样选择它时(从查询Exlorer和C#代码中都选择):
But when i try to select it like that (both from query exlorer and from c# code):
SELECT * FROM 357fa002-dc7d-4ede-935a-6a0c80cf9239 c
我得到:
语法错误,数字令牌'357fa002'无效.
Syntax error, invalid numeric value token '357fa002'.
我试图将它放在guid的引号(单引号和双引号)中,但没有成功.
I've tried to put it in quotation marks (both single and double) around guid but with no success..
Microsoft文档声明此集合ID不会违反任何规则: https://docs.microsoft.com/pl-pl/azure/documentdb/documentdb-create-collection
Microsoft docs state that this collection id doesn't break any rules: https://docs.microsoft.com/pl-pl/azure/documentdb/documentdb-create-collection
集合名称必须在1至255个字符之间,并且不能包含/\#?或尾随空格
Collection names must be between 1 and 255 characters, and cannot contain / \ # ? or a trailing space
如何使用其ID查询此收藏集?
How can i query this collection using it's id?
推荐答案
According to your description, I checked the official document about FROM clause of DocumentDB SQL Syntax. Here is the syntax from the above document:
FROM <from_specification>
<from_specification> ::=
<from_source> {[ JOIN <from_source>][,...n]}
<from_source> ::=
<collection_expression> [[AS] input_alias]
| input_alias IN <collection_expression>
<collection_expression> ::=
ROOT
| collection_name
| input_alias
| <collection_expression> '.' property_name
| <collection_expression> '[' "property_name" | array_index ']'
对于<collection_expression>
,我们可以指定当前连接到的集合的名称.
For <collection_expression>
, we could specify the name of the collection currently connected to.
根据您的情况,我尝试了此操作,并重现了此问题.另外,我测试了此问题,发现input_alias
或collection_name
只能由数字和字母组成,并且第一个必须是字母.根据我的测试,我认为您到目前为止无法实现此目的.我会报告此问题,您可以在此处添加反馈.
Based on your scenario, I tried it on my side and reproduced this issue. Also, I have tested this issue and found that the input_alias
or collection_name
could only made up of numbers and letters and the first must be a letter. Upon my test, I assumed that you couldn't achieve this purpose up to now. I would report this issue and you could add your feedback here.
更新:
对于用于C#的客户端库 Microsoft Azure Document ,我们可以利用 Fiddler 可以在调用DocumentClient.CreateDocumentQuery
时捕获请求,而无需指定sqlExpression
参数,如下所示:>
For the client libarary Microsoft Azure DocumentDB for C#, we could leverage Fiddler to capture the request when invoking DocumentClient.CreateDocumentQuery
without specifying the sqlExpression
parameter as follows:
var items =
client.CreateDocumentQuery<GroupedSales>(UriFactory.CreateDocumentCollectionUri(DatabaseId,
DocumentCollectionId)).Where(
x =>
x.Date >= filter.From.Date
&& x.Date <= filter.To.Date
).ToList();
注意:如果没有Where
子句,则请求正文为空.此时,查询等于"SELECT * FROM root".
Note: Without the Where
clause, the request body would be empty. At this point, the query equals to "SELECT * FROM root".
这篇关于如何从具有guid id的集合中选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!