我的Azure CosmosDB集合中有如下所示的DocumentDB。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="myselect" name="myselect">
<option value='161'>Option 1</option>
<option value='162'>Option 2</option>
<option value='163'>Option 3</option>
<option value='164'>Option 4</option>
</select>
<button type='button' class='btn btn-primary btn-xs' onClick="removeOption('161')">Option 1<span class='glyphicon glyphicon-remove' aria-hidden='true'></span></button>
<button type='button' class='btn btn-primary btn-xs' onClick="removeOption('162')">Option 2<span class='glyphicon glyphicon-remove' aria-hidden='true'></span></button>
<button type='button' class='btn btn-primary btn-xs' onClick="removeOption('163')">Option 3<span class='glyphicon glyphicon-remove' aria-hidden='true'></span></button>
<button type='button' class='btn btn-primary btn-xs' onClick="removeOption('164')">Option 4<span class='glyphicon glyphicon-remove' aria-hidden='true'></span></button>
我需要通过从文档中查询{
"TemplateID": "73",
"TemplateName": "Test -template",
"Read": [{
"devicename": "",
"timestamp": "2017-09-19T21:05:12.8550708+05:30",
"value": "038452735329RIV5"
},
{
"devicename": "",
"timestamp": "2017-09-19T21:05:12.8550708+05:30",
"value": "038452735330RIV5"
},
],
"eventTime": "2017-09-19T21:05:18.7954106+05:30",
}
{
"TemplateID": "73",
"TemplateName": "Test -template",
"Read": [{
"devicename": "",
"timestamp": "2017-09-19T21:05:12.8550708+05:30",
"value": "019452755319RIV5"
},
{
"devicename": "",
"timestamp": "2017-09-19T21:05:12.8550708+05:30",
"value": "138452715310RIV5"
},
],
"eventTime": "2017-09-19T21:05:18.7954106+05:30",
}
数组的value
节点来获取以下结构中的文档(例如,如果我输入代码Read
),我需要以下内容输出,
038452735329RIV5
我尝试了以下查询,
{
"TemplateID": "73",
"TemplateName": "Test -template",
"eventTime": "2017-09-19T21:05:18.7954106+05:30",
}
我没有收到所需的文件。我作为doc获取null,但AzureDB中存在文档。
任何人都可以查看并帮助我查询如何查询。
由于
答案 0 :(得分:0)
根据您的描述,我建议您尝试在documentdb中使用ARRAY_CONTAINS内置函数。
它可以检查数组中的值。
更多细节,您可以参考以下查询。
SELECT c.TemplateID,c.TemplateName,c.eventTime FROM c WHERE ARRAY_CONTAINS(c.Read, { 'value': '038452735329RIV5' }
结果:
C#代码:
string EndpointUrl = "xxxxxx";
string PrimaryKey = "xxxxxxxx";
DocumentClient client = new DocumentClient(new Uri(EndpointUrl), PrimaryKey);
FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };
var familyQuery = client.CreateDocumentQuery<test>(
UriFactory.CreateDocumentCollectionUri("testdb", "coll1"), "SELECT c.TemplateID,c.TemplateName,c.eventTime FROM c WHERE ARRAY_CONTAINS(c.Read, { 'value': '038452735329RIV5' }, true)", queryOptions).ToList();
结果: