}
// handle $all
if (queryValue instanceof BSONObject && ((BSONObject) queryValue).keySet().contains("$all")) {
// clone first
queryValue = new BasicBSONObject(((BSONObject) queryValue).toMap());
Object allQuery = ((BSONObject) queryValue).removeField("$all");
if (!checkMatchesAllDocuments(allQuery, keys, document)) {
return false;
}
// continue matching the remainder of queryValue
}
return checkMatchesAnyDocument(queryValue, keys, document);
}
if (!subKeys.isEmpty()) {
Object subObject = Utils.getListSafe(document, firstKey);
return checkMatch(queryValue, subKeys, subObject);
}
if (!(document instanceof BSONObject)) {
return false;
}
Object value = ((BSONObject) document).get(firstKey);
boolean valueExists = ((BSONObject) document).containsField(firstKey);
if (value instanceof Collection<?>) {
if (queryValue instanceof BSONObject) {
Set<String> keySet = ((BSONObject) queryValue).keySet();
// clone first
BSONObject queryValueClone = new BasicBSONObject(((BSONObject) queryValue).toMap());
for (String queryOperator : keySet) {
Object subQuery = queryValueClone.removeField(queryOperator);
if (queryOperator.equals(QueryOperator.ALL.getValue())) {
if (!checkMatchesAllValues(subQuery, value)) {
return false;
}
} else if (queryOperator.equals(QueryOperator.IN.getValue())) {
final BasicBSONObject inQuery = new BasicBSONObject(queryOperator, subQuery);
if (!checkMatchesAnyValue(inQuery, value))
return false;
} else if (queryOperator.equals(QueryOperator.NOT_IN.getValue())) {
if (checkMatchesAllValues(subQuery, value))
return false;