Skip to content

Commit a45742a

Browse files
authored
$lookup "from" must be null when using $documents pipeline (#1218)
JAVA-5190
1 parent 33aa2ba commit a45742a

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public static Bson lookup(final String from, final String localField, final Stri
310310
* the {@code from} collection is ignored.
311311
*
312312
* @param from the name of the collection in the same database to
313-
* perform the join with. May be {$code null} if the
313+
* perform the join with. Must be {$code null} if the
314314
* first pipeline stage is $documents.
315315
* @param pipeline the pipeline to run on the joined collection.
316316
* @param as the name of the new array field to add to the input documents.
@@ -332,7 +332,7 @@ public static Bson lookup(@Nullable final String from, final List<? extends Bson
332332
*
333333
* @param <TExpression> the Variable value expression type
334334
* @param from the name of the collection in the same database to
335-
* perform the join with. May be {$code null} if the
335+
* perform the join with. Must be {$code null} if the
336336
* first pipeline stage is $documents.
337337
* @param let the variables to use in the pipeline field stages.
338338
* @param pipeline the pipeline to run on the joined collection.

driver-core/src/test/functional/com/mongodb/client/model/AggregatesTest.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,12 @@ public void testDocumentsLookup() {
275275
getCollectionHelper().insertDocuments("[{_id: 1, a: 8}, {_id: 2, a: 9}]");
276276
Bson documentsStage = Aggregates.documents(asList(Document.parse("{a: 5}")));
277277

278-
Bson lookupStage = Aggregates.lookup("ignored", Arrays.asList(documentsStage), "added");
278+
Bson lookupStage = Aggregates.lookup(null, Arrays.asList(documentsStage), "added");
279279
assertPipeline(
280-
"{'$lookup': {'from': 'ignored', 'pipeline': [{'$documents': [{'a': 5}]}], 'as': 'added'}}",
280+
"{'$lookup': {'pipeline': [{'$documents': [{'a': 5}]}], 'as': 'added'}}",
281281
lookupStage);
282282
assertEquals(
283283
parseToList("[{_id:1, a:8, added: [{a: 5}]}, {_id:2, a:9, added: [{a: 5}]}]"),
284284
getCollectionHelper().aggregate(Arrays.asList(lookupStage)));
285-
286-
// null variant
287-
Bson lookupStageNull = Aggregates.lookup(null, Arrays.asList(documentsStage), "added");
288-
assertPipeline(
289-
"{'$lookup': {'pipeline': [{'$documents': [{'a': 5}]}], 'as': 'added'}}",
290-
lookupStageNull);
291-
assertEquals(
292-
parseToList("[{_id:1, a:8, added: [{a: 5}]}, {_id:2, a:9, added: [{a: 5}]}]"),
293-
getCollectionHelper().aggregate(Arrays.asList(lookupStageNull)));
294285
}
295286
}

0 commit comments

Comments
 (0)