Skip to content

Commit e08a32c

Browse files
committed
Forcefully casting array as list to avoid compatibility issues in mongodb
1 parent 03b7c77 commit e08a32c

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/main/java/picoded/dstack/mongodb/MongoDB_DataObjectMap.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full
243243
value = new Binary((byte[]) value);
244244
}
245245

246+
// If value is an array, cast it to the list, as mongoDB has issues with arrays
247+
if (value != null && value.getClass().isArray()) {
248+
value = Arrays.asList(value);
249+
}
250+
246251
// Lets apply the update values
247252
if (updateKeys.contains(key)) {
248253
// Handle NULL values unset
@@ -363,18 +368,19 @@ static protected Bson queryObjToBsonFilter(Query inQuery) {
363368
// Because the LIKE operator does not natively exists,
364369
// we will generates its REGEX equivalent
365370
String val = GenericConvert.toString(inQuery.defaultArgumentValue());
366-
371+
367372
// Escaping special regex characters
368373
final String regexSpecialCharacters = ".+*?^$()[]{}|\\";
369-
for(int i=0; i<regexSpecialCharacters.length(); ++i) {
370-
val = val.replaceAll("\\"+regexSpecialCharacters.charAt(i), "\\"+regexSpecialCharacters.charAt(i));
374+
for (int i = 0; i < regexSpecialCharacters.length(); ++i) {
375+
val = val.replaceAll("\\" + regexSpecialCharacters.charAt(i), "\\"
376+
+ regexSpecialCharacters.charAt(i));
371377
}
372-
378+
373379
// Replacing SQL syntax
374380
val = val.replaceAll("\\%", ".*");
375381
val = val.replaceAll("\\_", ".");
376382

377-
return Filters.regex(inQuery.fieldName(), "^"+val+"$");
383+
return Filters.regex(inQuery.fieldName(), "^" + val + "$");
378384
}
379385
}
380386

0 commit comments

Comments
 (0)