From 9806fdcf7a20d3289bcfcda330a808e65dbcdbd0 Mon Sep 17 00:00:00 2001 From: Maxim Katcharov Date: Thu, 5 Oct 2023 11:01:52 -0600 Subject: [PATCH] $lookup "from" must be null when using $documents pipeline --- .../main/com/mongodb/client/model/Aggregates.java | 4 ++-- .../com/mongodb/client/model/AggregatesTest.java | 13 ++----------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/driver-core/src/main/com/mongodb/client/model/Aggregates.java b/driver-core/src/main/com/mongodb/client/model/Aggregates.java index 60980a6c481..08e2fb10b02 100644 --- a/driver-core/src/main/com/mongodb/client/model/Aggregates.java +++ b/driver-core/src/main/com/mongodb/client/model/Aggregates.java @@ -310,7 +310,7 @@ public static Bson lookup(final String from, final String localField, final Stri * the {@code from} collection is ignored. * * @param from the name of the collection in the same database to - * perform the join with. May be {$code null} if the + * perform the join with. Must be {$code null} if the * first pipeline stage is $documents. * @param pipeline the pipeline to run on the joined collection. * @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 the Variable value expression type * @param from the name of the collection in the same database to - * perform the join with. May be {$code null} if the + * perform the join with. Must be {$code null} if the * first pipeline stage is $documents. * @param let the variables to use in the pipeline field stages. * @param pipeline the pipeline to run on the joined collection. diff --git a/driver-core/src/test/functional/com/mongodb/client/model/AggregatesTest.java b/driver-core/src/test/functional/com/mongodb/client/model/AggregatesTest.java index 719d895ff41..1ed7d6de836 100644 --- a/driver-core/src/test/functional/com/mongodb/client/model/AggregatesTest.java +++ b/driver-core/src/test/functional/com/mongodb/client/model/AggregatesTest.java @@ -275,21 +275,12 @@ public void testDocumentsLookup() { getCollectionHelper().insertDocuments("[{_id: 1, a: 8}, {_id: 2, a: 9}]"); Bson documentsStage = Aggregates.documents(asList(Document.parse("{a: 5}"))); - Bson lookupStage = Aggregates.lookup("ignored", Arrays.asList(documentsStage), "added"); + Bson lookupStage = Aggregates.lookup(null, Arrays.asList(documentsStage), "added"); assertPipeline( - "{'$lookup': {'from': 'ignored', 'pipeline': [{'$documents': [{'a': 5}]}], 'as': 'added'}}", + "{'$lookup': {'pipeline': [{'$documents': [{'a': 5}]}], 'as': 'added'}}", lookupStage); assertEquals( parseToList("[{_id:1, a:8, added: [{a: 5}]}, {_id:2, a:9, added: [{a: 5}]}]"), getCollectionHelper().aggregate(Arrays.asList(lookupStage))); - - // null variant - Bson lookupStageNull = Aggregates.lookup(null, Arrays.asList(documentsStage), "added"); - assertPipeline( - "{'$lookup': {'pipeline': [{'$documents': [{'a': 5}]}], 'as': 'added'}}", - lookupStageNull); - assertEquals( - parseToList("[{_id:1, a:8, added: [{a: 5}]}, {_id:2, a:9, added: [{a: 5}]}]"), - getCollectionHelper().aggregate(Arrays.asList(lookupStageNull))); } }