Starts-With Query
-
You can query for documents having a field that starts with some specified string.
-
Unless explicitly specified, the string comparisons are case-insensitive by default.
-
In this page:
StartsWith
List<Product> products = session
.Query<Product>()
// Call 'StartsWith' on the field
// Pass the prefix to search by
.Where(x => x.Name.StartsWith("Ch"))
.ToList();
// Results will contain only Product documents having a 'Name' field
// that starts with any case variation of 'ch'
List<Product> products = await asyncSession
.Query<Product>()
// Call 'StartsWith' on the field
// Pass the prefix to search by
.Where(x => x.Name.StartsWith("Ch"))
.ToListAsync();
// Results will contain only Product documents having a 'Name' field
// that starts with any case variation of 'ch'
List<Product> products = session.Advanced
.DocumentQuery<Product>()
// Call 'WhereStartsWith'
// Pass the document field and the prefix to search by
.WhereStartsWith(x => x.Name, "Ch")
.ToList();
// Results will contain only Product documents having a 'Name' field
// that starts with any case variation of 'ch'
from "Products"
where startsWith(Name, "Ch")
StartsWith (case-sensitive)
List<Product> products = session
.Query<Product>()
// Pass 'exact: true' to search for an EXACT prefix match
.Where(x => x.Name.StartsWith("Ch"), exact: true)
.ToList();
// Results will contain only Product documents having a 'Name' field
// that starts with 'Ch'
List<Product> products = await asyncSession
.Query<Product>()
// Pass 'exact: true' to search for an EXACT prefix match
.Where(x => x.Name.StartsWith("Ch"), exact: true)
.ToListAsync();
// Results will contain only Product documents having a 'Name' field
// that starts with 'Ch'
List<Product> products = session.Advanced
.DocumentQuery<Product>()
// Call 'WhereStartsWith'
// Pass 'exact: true' to search for an EXACT prefix match
.WhereStartsWith(x => x.Name, "Ch", exact: true)
.ToList();
// Results will contain only Product documents having a 'Name' field
// that starts with 'Ch'
from "Products"
where exact(startsWith(Name, "Ch"))
Negate StartsWith
List<Product> products = session
.Query<Product>()
// Call 'StartsWith' on the field
// Pass the prefix to search by
.Where(x => x.Name.StartsWith("Ch") == false)
.ToList();
// Results will contain only Product documents having a 'Name' field
// that does NOT start with 'ch' or any other case variations of it
List<Product> products = await asyncSession
.Query<Product>()
// Call 'StartsWith' on the field
// Pass the prefix to search by
.Where(x => x.Name.StartsWith("Ch") == false)
.ToListAsync();
// Results will contain only Product documents having a 'Name' field
// that does NOT start with 'ch' or any other case variations of it
List<Product> products = session.Advanced
.DocumentQuery<Product>()
// Call 'Not' to negate the next predicate
.Not
// Call 'WhereStartsWith'
// Pass the document field and the prefix to search by
.WhereStartsWith(x => x.Name, "Ch")
.ToList();
// Results will contain only Product documents having a 'Name' field
// that does NOT start with 'ch' or any other case variations of it
from "Products"
where (true and not startsWith(Name, "Ch"))