Skip to content

Commit 27dafda

Browse files
committed
JAVA-2093: Add overloaded eq method to Filters to filter by the value of the _id field
1 parent bf7c8aa commit 27dafda

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

driver-core/src/main/com/mongodb/client/model/Filters.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ public final class Filters {
5353
private Filters() {
5454
}
5555

56+
/**
57+
* Creates a filter that matches all documents where the value of _id field equalss the specified value. Note that this does
58+
* actually generate a $eq operator, as the query language doesn't require it.
59+
*
60+
* @param value the value
61+
* @param <TItem> the value type
62+
* @return the filter
63+
* @mongodb.driver.manual reference/operator/query/eq $eq
64+
*
65+
* @since 3.4
66+
*/
67+
public static <TItem> Bson eq(final TItem value) {
68+
return eq("_id", value);
69+
}
70+
5671
/**
5772
* Creates a filter that matches all documents where the value of the field name equals the specified value. Note that this does
5873
* actually generate a $eq operator, as the query language doesn't require it.

driver-core/src/test/functional/com/mongodb/client/model/FiltersFunctionalSpecification.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class FiltersFunctionalSpecification extends OperationFunctionalSpecification {
7878
def 'eq'() {
7979
expect:
8080
find(eq('x', 1)) == [a]
81+
find(eq(2)) == [b]
8182
}
8283

8384
def '$ne'() {

driver-core/src/test/unit/com/mongodb/client/model/FiltersSpecification.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class FiltersSpecification extends Specification {
8080
expect:
8181
toBson(eq('x', 1)) == parse('{x : 1}')
8282
toBson(eq('x', null)) == parse('{x : null}')
83+
toBson(eq(1)) == parse('{_id : 1}')
8384
}
8485

8586
def 'should render $ne'() {

0 commit comments

Comments
 (0)