在 documentDB 中按子字符串搜索
search by substring in documentDB
这是示例 documentDB 文档,
我想获取一个或多个科目不及格的所有文档
我发现了类似的东西
SELECT
*
FROM students s
JOIN c IN s.subjects
WHERE c.result = "pass"
我想用c#代码检索
{
"id": "0066a253-f042-4213-b06e-65b1ea1e49aa",
"name": "Sunny",
"rollNo": 123,
"class": "2nd",
"section": "B",
"Department": {
"name": "CSE",
"id": "cse",
"subjects": [
{
"id": "subject-1",
"marksObtained": 66,
"maxMarks": 100,
"result": "pass"
},
{
"id": "subject-2",
"marksObtained": 56,
"maxMarks": 75,
"result": "pass"
},
{
"id": "subject-3",
"marksObtained": 22,
"maxMarks": 100,
"result": "fail"
},
{
"id": "subject-4",
"marksObtained": 36,
"maxMarks": 50,
"result": "pass"
},
{
"id": "subject-5",
"marksObtained": 16,
"maxMarks": 100,
"result": "fail"
}
]
},
"Type": "Student"
}
我试过这样
var result = client.CreateDocumentQuery<dynamic>(dc.SelfLink, "SELECT s.id as id,s.Name as Name,s.Age as Age,s.section as section,s.subjects as subjects FROM students s JOIN c IN s.subjects WHERE c.result = \"pass\"").ToList();
List<Student> students = new List<Student>();
foreach(var std in result)
{
students.Add((Student)std);
}
上面的内容是我得到的代码,但即使我给出 pa 或 pas 或 pass 或 p 或 ass 或那样我也应该得到一些我需要 SQL[= 中的 LIKE 功能的东西13=]
请问有解决办法吗??
我需要 SQL 中的 LIKE 功能来从 documentDB
中检索数据
更新:从 5/6/15 开始,DocumentDB 添加了一组字符串函数,包括 STARTSWITH
、ENDSWITH
和 CONTAINS
。请注意,这些函数中的大多数不会 运行 索引并会强制扫描。
像 SQL 的 LIKE '% %' 这样的通配符尚未在 DocumentDB .
中实现
请在 DocumentDB's feedback forum 上表达您的意见并为此功能投票。
最近几个月引入了一些新功能。对于您的特殊情况,我认为您可以使用:
WHERE STARTSWITH(c.result, "p")
这是示例 documentDB 文档,
我想获取一个或多个科目不及格的所有文档
我发现了类似的东西
SELECT
*
FROM students s
JOIN c IN s.subjects
WHERE c.result = "pass"
我想用c#代码检索
{
"id": "0066a253-f042-4213-b06e-65b1ea1e49aa",
"name": "Sunny",
"rollNo": 123,
"class": "2nd",
"section": "B",
"Department": {
"name": "CSE",
"id": "cse",
"subjects": [
{
"id": "subject-1",
"marksObtained": 66,
"maxMarks": 100,
"result": "pass"
},
{
"id": "subject-2",
"marksObtained": 56,
"maxMarks": 75,
"result": "pass"
},
{
"id": "subject-3",
"marksObtained": 22,
"maxMarks": 100,
"result": "fail"
},
{
"id": "subject-4",
"marksObtained": 36,
"maxMarks": 50,
"result": "pass"
},
{
"id": "subject-5",
"marksObtained": 16,
"maxMarks": 100,
"result": "fail"
}
]
},
"Type": "Student"
}
我试过这样
var result = client.CreateDocumentQuery<dynamic>(dc.SelfLink, "SELECT s.id as id,s.Name as Name,s.Age as Age,s.section as section,s.subjects as subjects FROM students s JOIN c IN s.subjects WHERE c.result = \"pass\"").ToList();
List<Student> students = new List<Student>();
foreach(var std in result)
{
students.Add((Student)std);
}
上面的内容是我得到的代码,但即使我给出 pa 或 pas 或 pass 或 p 或 ass 或那样我也应该得到一些我需要 SQL[= 中的 LIKE 功能的东西13=]
请问有解决办法吗?? 我需要 SQL 中的 LIKE 功能来从 documentDB
中检索数据更新:从 5/6/15 开始,DocumentDB 添加了一组字符串函数,包括 STARTSWITH
、ENDSWITH
和 CONTAINS
。请注意,这些函数中的大多数不会 运行 索引并会强制扫描。
像 SQL 的 LIKE '% %' 这样的通配符尚未在 DocumentDB .
中实现请在 DocumentDB's feedback forum 上表达您的意见并为此功能投票。
最近几个月引入了一些新功能。对于您的特殊情况,我认为您可以使用:
WHERE STARTSWITH(c.result, "p")