Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

search by substring in documentDB

this is the sample documentDB document,

I want to get all the documents who failed in one or more subjects

I found something like

SELECT 
    *
FROM students s 
JOIN c IN s.subjects 
WHERE c.result = "pass"

I want to retrieve by using 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"
}

i tried like this

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); 
} 

Something like above is my code I am getting, but Even I give pa or pas or pass or p or ass or as then also I should get something I need a functionality of LIKE in SQL

Is there any solution for this?? I need LIKE functionality in SQL to retrieve data from documentDB

like image 554
satish kumar V Avatar asked Jan 02 '15 10:01

satish kumar V


2 Answers

Update: As of 5/6/15, DocumentDB added a set of String functions including STARTSWITH, ENDSWITH, and CONTAINS. Please note that most of these functions do not run on the index and will force a scan.

Wildcards like SQL's LIKE '% %' has not been implemented in DocumentDB yet.

Please voice your opinion and vote for this feature on DocumentDB's feedback forum.

like image 135
Andrew Liu Avatar answered Nov 15 '22 12:11

Andrew Liu


Some new functions have been introduced in the last few months. For you particular case I think you can use:

WHERE STARTSWITH(c.result, "p")
like image 35
ciobi Avatar answered Nov 15 '22 12:11

ciobi