Azure DocumentDB-查询不返回任何结果
Azure DocumentDB是否支持以下查询?它不返回任何文档Azure DocumentDB-查询不返回任何结果,azure,azure-cosmosdb,Azure,Azure Cosmosdb,Azure DocumentDB是否支持以下查询?它不返回任何文档 Variables values at runtime: 1. collectionLink = "<link for my collection>" 2. feedOptions = new FeedOptions { MaxItemCount = 2 } 3. name = "chris" client.CreateDocumentQuery<T>(collectionLink, fee
Variables values at runtime:
1. collectionLink = "<link for my collection>"
2. feedOptions = new FeedOptions { MaxItemCount = 2 }
3. name = "chris"
client.CreateDocumentQuery<T>(collectionLink, feedOptions).Where(m => (m.Status == "Foo" && (m.Black.Name == null || m.Black.Name != name) && (m.White.Name == null || m.White.Name != name)));
谢谢。发现“m.White.Name==null | | m.White.Name!=Name”检查有问题,因为数据库中的文档上不存在Name字段
将文档编辑为以下内容时,查询将返回该文档。请注意Name字段的显式空值
{
"id": "1992db52-c9c6-4496-aaaa-f8cb83a8c6b0",
"status": "Foo",
"size": 19,
"black": {
"name": "charlie"
},
"white": {
"name": null
},
}
可以编写查询以使用DocumentDB UDF处理缺少的属性,如下所示。DocumentDB使用JavaScript的语义,显式null与JavaScript中缺少的属性(“未定义”)不同。检查显式null很简单(=与您的查询一样为null),但要查询DocumentDB中可能存在或不存在的字段,必须首先为ISDEFINED创建一个UDF:
function ISDEFINED(doc, prop) {
return doc[prop] !== undefined;
}
然后在DocumentDB查询中使用它,如:
client.CreateDocumentQuery<T>(
collectionLink,
"SELECT * FROM docs m WHERE m.Status == "Foo" AND (ISDEFINED(m.white, "name") OR m.white.name != name)");
client.CreateDocumentQuery(
收集链接,
“从文档m中选择*,其中m.Status==“Foo”和(ISDEFINED(m.white,“name”)或m.white.name!=name)”;
希望这有帮助。请注意,自UDF和UDF都需要扫描,对于性能/规模来说,最好只在具有其他筛选器的查询中使用它们。我看到现在是一个标准的类型检查函数。这是在你写上述内容和现在之间添加的,还是你的UDF有什么不同的地方,是我没有看到的定义?
function ISDEFINED(doc, prop) {
return doc[prop] !== undefined;
}
client.CreateDocumentQuery<T>(
collectionLink,
"SELECT * FROM docs m WHERE m.Status == "Foo" AND (ISDEFINED(m.white, "name") OR m.white.name != name)");