Does DocumentDB support the LIKE keyword in queries?

Joker_37 picture Joker_37 · Apr 16, 2016 · Viewed 12.3k times · Source

Can we use the LIKE keyword to filter out records as we use it in T-SQL?

Answer

cnaegle picture cnaegle · Apr 16, 2016

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