Skip to content

$lookup "from" must be null when using $documents pipeline #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions driver-core/src/main/com/mongodb/client/model/Aggregates.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -332,7 +332,7 @@ public static Bson lookup(@Nullable final String from, final List<? extends Bson
*
* @param <TExpression> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}