Skip to content

Commit 0c5a79d

Browse files
authored
Add comment option tests for distinct helper (#974)
Allow query field with empty value JAVA-4627
1 parent 7951241 commit 0c5a79d

File tree

3 files changed

+182
-2
lines changed

3 files changed

+182
-2
lines changed

driver-core/src/main/com/mongodb/internal/operation/DistinctOperation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import static com.mongodb.internal.operation.CommandOperationHelper.executeRetryableRead;
4747
import static com.mongodb.internal.operation.CommandOperationHelper.executeRetryableReadAsync;
4848
import static com.mongodb.internal.operation.DocumentHelper.putIfNotNull;
49-
import static com.mongodb.internal.operation.DocumentHelper.putIfNotNullOrEmpty;
5049
import static com.mongodb.internal.operation.DocumentHelper.putIfNotZero;
5150
import static com.mongodb.internal.operation.OperationHelper.LOGGER;
5251
import static com.mongodb.internal.operation.OperationHelper.validateReadConcernAndCollation;
@@ -259,7 +258,7 @@ private BsonDocument getCommand(final SessionContext sessionContext, final Conne
259258
BsonDocument commandDocument = new BsonDocument("distinct", new BsonString(namespace.getCollectionName()));
260259
appendReadConcernToCommand(sessionContext, connectionDescription.getMaxWireVersion(), commandDocument);
261260
commandDocument.put("key", new BsonString(fieldName));
262-
putIfNotNullOrEmpty(commandDocument, "query", filter);
261+
putIfNotNull(commandDocument, "query", filter);
263262
putIfNotZero(commandDocument, "maxTimeMS", maxTimeMS);
264263
if (collation != null) {
265264
commandDocument.put("collation", collation.asDocument());
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
{
2+
"description": "distinct-comment",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"observeEvents": [
9+
"commandStartedEvent"
10+
]
11+
}
12+
},
13+
{
14+
"database": {
15+
"id": "database0",
16+
"client": "client0",
17+
"databaseName": "distinct-comment-tests"
18+
}
19+
},
20+
{
21+
"collection": {
22+
"id": "collection0",
23+
"database": "database0",
24+
"collectionName": "coll0"
25+
}
26+
}
27+
],
28+
"initialData": [
29+
{
30+
"collectionName": "coll0",
31+
"databaseName": "distinct-comment-tests",
32+
"documents": [
33+
{
34+
"_id": 1,
35+
"x": 11
36+
},
37+
{
38+
"_id": 2,
39+
"x": 22
40+
},
41+
{
42+
"_id": 3,
43+
"x": 33
44+
}
45+
]
46+
}
47+
],
48+
"tests": [
49+
{
50+
"description": "distinct with document comment",
51+
"runOnRequirements": [
52+
{
53+
"minServerVersion": "4.4.14"
54+
}
55+
],
56+
"operations": [
57+
{
58+
"name": "distinct",
59+
"object": "collection0",
60+
"arguments": {
61+
"fieldName": "x",
62+
"filter": {},
63+
"comment": {
64+
"key": "value"
65+
}
66+
},
67+
"expectResult": [ 11, 22, 33 ]
68+
}
69+
],
70+
"expectEvents": [
71+
{
72+
"client": "client0",
73+
"events": [
74+
{
75+
"commandStartedEvent": {
76+
"command": {
77+
"distinct": "coll0",
78+
"key": "x",
79+
"query": {},
80+
"comment": {
81+
"key": "value"
82+
}
83+
},
84+
"commandName": "distinct",
85+
"databaseName": "distinct-comment-tests"
86+
}
87+
}
88+
]
89+
}
90+
]
91+
},
92+
{
93+
"description": "distinct with string comment",
94+
"runOnRequirements": [
95+
{
96+
"minServerVersion": "4.4.0"
97+
}
98+
],
99+
"operations": [
100+
{
101+
"name": "distinct",
102+
"object": "collection0",
103+
"arguments": {
104+
"fieldName": "x",
105+
"filter": {},
106+
"comment": "comment"
107+
},
108+
"expectResult": [ 11, 22, 33 ]
109+
}
110+
],
111+
"expectEvents": [
112+
{
113+
"client": "client0",
114+
"events": [
115+
{
116+
"commandStartedEvent": {
117+
"command": {
118+
"distinct": "coll0",
119+
"key": "x",
120+
"query": {},
121+
"comment": "comment"
122+
},
123+
"commandName": "distinct",
124+
"databaseName": "distinct-comment-tests"
125+
}
126+
}
127+
]
128+
}
129+
]
130+
},
131+
{
132+
"description": "distinct with document comment - pre 4.4, server error",
133+
"runOnRequirements": [
134+
{
135+
"minServerVersion": "3.6.0",
136+
"maxServerVersion": "4.4.13"
137+
}
138+
],
139+
"operations": [
140+
{
141+
"name": "distinct",
142+
"object": "collection0",
143+
"arguments": {
144+
"fieldName": "x",
145+
"filter": {},
146+
"comment": {
147+
"key": "value"
148+
}
149+
},
150+
"expectError": {
151+
"isClientError": false
152+
}
153+
}
154+
],
155+
"expectEvents": [
156+
{
157+
"client": "client0",
158+
"events": [
159+
{
160+
"commandStartedEvent": {
161+
"command": {
162+
"distinct": "coll0",
163+
"key": "x",
164+
"query": {},
165+
"comment": {
166+
"key": "value"
167+
}
168+
},
169+
"commandName": "distinct",
170+
"databaseName": "distinct-comment-tests"
171+
}
172+
}
173+
]
174+
}
175+
]
176+
}
177+
]
178+
}

driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ OperationResult executeDistinct(final BsonDocument operation) {
328328
case "fieldName":
329329
case "session":
330330
break;
331+
case "comment":
332+
iterable.comment(cur.getValue());
333+
break;
331334
case "filter":
332335
iterable.filter(cur.getValue().asDocument());
333336
break;

0 commit comments

Comments
 (0)