在documentDB中搜索substring

时间:2015-01-02 10:05:59

标签: c# search sql-like azure-cosmosdb

这是示例documentDB文档,

我希望获得一个或多个科目失败的所有文件

我找到了像

这样的东西
SELECT 
    *
FROM students s 
JOIN c IN s.subjects 
WHERE c.result = "pass"

我想使用c#code

进行检索
{
  "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的功能

有没有解决方案? 我需要SQL中的LIKE功能来从documentDB中检索数据

2 个答案:

答案 0 :(得分:8)

更新:自5/6/15起,DocumentDB添加了一组字符串函数,包括STARTSWITHENDSWITHCONTAINS。请注意,大多数这些功能都不会在索引上运行,并会强制进行扫描。

像SQL&#39; %%&#39;这样的通配符尚未在DocumentDB 中实现

请在DocumentDB's feedback forum上表达您的意见并投票支持此功能。

答案 1 :(得分:5)

过去几个月推出了一些新功能。对于你的特殊情况,我认为你可以使用:

WHERE STARTSWITH(c.result, "p")