Java Code Examples for com.mongodb.client.model.Filters#regex()
The following examples show how to use
com.mongodb.client.model.Filters#regex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateBsonPredicateVisitor.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public Function<String, Bson> visitLike(final String value) { // remove leading or trailing wildcard because queries like /^a/ are much faster than /^a.*$/ or /^a.*/ // from mongodb docs: // "Additionally, while /^a/, /^a.*/, and /^a.*$/ match equivalent strings, they have different performance // characteristics. All of these expressions use an index if an appropriate index exists; // however, /^a.*/, and /^a.*$/ are slower. /^a/ can stop scanning after matching the prefix." final String valueWithoutLeadingOrTrailingWildcard = removeLeadingOrTrailingWildcard(value); return fieldName -> Filters.regex(fieldName, valueWithoutLeadingOrTrailingWildcard, ""); }
Example 2
Source File: MongoRepository.java From javers with Apache License 2.0 | 4 votes |
private static Bson prefixQuery(String fieldName, String prefix){ return Filters.regex(fieldName, "^" + RegexEscape.escape(prefix) + ".*"); }