Can we use the LIKE
keyword to filter out records as we use it in T-SQL?
Asked
Active
Viewed 1.3k times
28
1 Answers
42
The keyword for LIKE
is CONTAINS
. If you had a document with a firstName
property and you wanted to filter on the name 'bob'
you would use it in a query this way:
"SELECT * FROM c WHERE CONTAINS(c.firstName, 'bob')"
Or if you were using Linq
and assuming you had a class Person
with a FirstName
property the same query would work this way:
var dbClient = GetClient();
var docs = dbClient.CreateDocumentQuery<Person>(Collection)
.Where(p => p.FirstName.Contains("bob");

cnaegle
- 1,125
- 1
- 10
- 12
-
4Agree with the comment above. If you'd like to see LIKE added in the DocumentDB query grammar, please up-vote here: https://feedback.azure.com/forums/263030-documentdb/suggestions/6333414-implement-wildcards-when-searching – Aravind Krishna R. Apr 16 '16 at 16:29
-
2A couple more `%`-like options from Aravind's link: "*Azure Cosmos DB supports the CONTAINS, **STARTSWITH, and ENDSWITH** built-in functions which are equivalent to LIKE.*" (emph mine, natch) – ruffin Sep 19 '18 at 14:48