Skip to content

Commit dde3c66

Browse files
authored
Merge pull request #321 from martiner/ne
make $ne operator type handling consistent with $eq
2 parents 48ae099 + e7ccceb commit dde3c66

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main/java/com/github/fakemongo/impl/ExpressionParser.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ private boolean isEqual(Object obj1, Object obj2) {
182182
return false;
183183
}
184184

185-
return obj1.equals(obj2);
185+
Integer result = compareObjects(obj1, obj2, true);
186+
return result != null && result.intValue() == 0;
186187
}
187188
};
188189
}

src/test/java/com/github/fakemongo/impl/ExpressionParserTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public void testBasicOperators() {
109109
assertQuery(new BasicDBObject("a", new BasicDBObject("$eq", 1)), Arrays.<DBObject>asList(
110110
new BasicDBObject("n", "neil").append("a", 1)
111111
));
112+
assertQuery(new BasicDBObject("a", new BasicDBObject("$eq", 1L)), Arrays.<DBObject>asList(
113+
new BasicDBObject("n", "neil").append("a", 1)
114+
));
112115
}
113116

114117
@Test
@@ -152,6 +155,20 @@ public void testNeOperator() {
152155
), results);
153156
}
154157

158+
@Test
159+
public void testNeOperatorDifferentTypes() {
160+
DBObject query = new BasicDBObjectBuilder().push("a").add("$ne", 1L).pop().get();
161+
162+
List<DBObject> results = doFilter(
163+
query,
164+
new BasicDBObject("a", 1),
165+
new BasicDBObject("a", 2)
166+
);
167+
assertEquals(Collections.<DBObject>singletonList(
168+
new BasicDBObject("a", 2)
169+
), results);
170+
}
171+
155172
@Test
156173
public void testNeOperatorWithNullValue() {
157174
DBObject query = new BasicDBObjectBuilder().push("a").add("$ne", null).pop().get();

0 commit comments

Comments
 (0)