|
29 | 29 | import java.util.stream.Collectors;
|
30 | 30 |
|
31 | 31 | import org.bson.BsonRegularExpression;
|
| 32 | +import org.bson.BsonType; |
32 | 33 | import org.bson.Document;
|
33 | 34 | import org.bson.types.Binary;
|
34 | 35 | import org.springframework.data.domain.Example;
|
@@ -188,6 +189,42 @@ public Criteria is(@Nullable Object value) {
|
188 | 189 | return this;
|
189 | 190 | }
|
190 | 191 |
|
| 192 | + /** |
| 193 | + * Creates a criterion using {@literal null} equality comparison which matches documents that either contain the item |
| 194 | + * field whose value is {@literal null} or that do not contain the item field. |
| 195 | + * <p /> |
| 196 | + * Use {@link #isNullValue()} to only query for documents that contain the field whose value is equal to |
| 197 | + * {@link org.bson.BsonType#NULL}. <br /> |
| 198 | + * Use {@link #exists(boolean)} to query for documents that do (not) contain the field. |
| 199 | + * |
| 200 | + * @return this. |
| 201 | + * @see <a href="https://docs.mongodb.com/manual/tutorial/query-for-null-fields/#equality-filter">Query for Null or |
| 202 | + * Missing Fields: Equality Filter</a> |
| 203 | + * @since 3.3 |
| 204 | + */ |
| 205 | + public Criteria isNull() { |
| 206 | + return is(null); |
| 207 | + } |
| 208 | + |
| 209 | + /** |
| 210 | + * Creates a criterion using a {@link org.bson.BsonType} comparison which matches only documents that contain the item |
| 211 | + * field whose value is equal to {@link org.bson.BsonType#NULL}. |
| 212 | + * <p /> |
| 213 | + * Use {@link #isNull()} to query for documents that contain the field with a {@literal null} value or do not contain the |
| 214 | + * field at all. <br /> |
| 215 | + * Use {@link #exists(boolean)} to query for documents that do (not) contain the field. |
| 216 | + * |
| 217 | + * @return this. |
| 218 | + * @see <a href="https://docs.mongodb.com/manual/tutorial/query-for-null-fields/#type-check">Query for Null or Missing |
| 219 | + * Fields: Type Check</a> |
| 220 | + * @since 3.3 |
| 221 | + */ |
| 222 | + public Criteria isNullValue() { |
| 223 | + |
| 224 | + criteria.put("$type", BsonType.NULL.getValue()); |
| 225 | + return this; |
| 226 | + } |
| 227 | + |
191 | 228 | private boolean lastOperatorWasNot() {
|
192 | 229 | return !this.criteria.isEmpty() && "$not".equals(this.criteria.keySet().toArray()[this.criteria.size() - 1]);
|
193 | 230 | }
|
|
0 commit comments