|
1 | 1 | package picoded.dstack.mongodb; |
2 | 2 |
|
3 | 3 | // Java imports |
| 4 | +import java.util.regex.Pattern; |
4 | 5 | import java.util.HashMap; |
5 | 6 | import java.util.HashSet; |
6 | 7 | import java.util.List; |
@@ -293,13 +294,12 @@ public Set<String> keySet() { |
293 | 294 | HashSet<String> ret = new HashSet<String>(); |
294 | 295 |
|
295 | 296 | // Lets fetch everything ... D= |
296 | | - FindIterable<Document> search = collection.find(); |
297 | | - search = search.projection(Projections.include("_oid")); |
| 297 | + DistinctIterable<String> search = collection.distinct("_oid", String.class); |
298 | 298 |
|
299 | 299 | // Lets iterate the search |
300 | | - try (MongoCursor<Document> cursor = search.iterator()) { |
| 300 | + try (MongoCursor<String> cursor = search.iterator()) { |
301 | 301 | while (cursor.hasNext()) { |
302 | | - ret.add(cursor.next().getString("_oid")); |
| 302 | + ret.add(cursor.next()); |
303 | 303 | } |
304 | 304 | } |
305 | 305 |
|
@@ -362,13 +362,14 @@ static protected Bson queryObjToBsonFilter(Query inQuery) { |
362 | 362 | if (type == QueryType.LIKE) { |
363 | 363 | // Because the LIKE operator does not natively exists, |
364 | 364 | // we will generates its REGEX equivalent |
365 | | - |
366 | 365 | String val = GenericConvert.toString(inQuery.defaultArgumentValue()); |
367 | | - val = val.replaceAll("*", "\\*"); |
| 366 | + |
| 367 | + // val = val.replaceAll("*", "*"); |
| 368 | + val = val.replaceAll("*", Pattern.quote("*")); |
368 | 369 | val = val.replaceAll("%", ".*"); |
369 | | - val = val.replaceAll("_", ".+"); |
| 370 | + val = val.replaceAll("_", "[.]"); |
370 | 371 |
|
371 | | - return Filters.regex(inQuery.fieldName(), val); |
| 372 | + return Filters.regex(inQuery.fieldName(), "^"+val+"$"); |
372 | 373 | } |
373 | 374 | } |
374 | 375 |
|
|
0 commit comments