Skip to content
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

fix(NODE-3467): allow object type for aggregate out helper #2971

Merged
merged 1 commit into from Sep 3, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cursor/aggregation_cursor.ts
Expand Up @@ -121,7 +121,7 @@ export class AggregationCursor<TSchema = Document> extends AbstractCursor<TSchem
}

/** Add an out stage to the aggregation pipeline */
out($out: string): this {
out($out: { db: string; coll: string } | string): this {
assertUninitialized(this);
this[kPipeline].push({ $out });
return this;
Expand Down
10 changes: 8 additions & 2 deletions test/types/mongodb.test-d.ts
Expand Up @@ -37,5 +37,11 @@ expectType<string | null>(await composedMap.next());
expectType<string[]>(await composedMap.toArray());

const builtCursor = coll.aggregate();
expectType<AggregationCursor<Document>>(builtCursor.out('string')); // should allow string values for the out helper
expectError(builtCursor.out(1)); // should error on non-string values
// should allow string values for the out helper
expectType<AggregationCursor<Document>>(builtCursor.out('collection'));
// should also allow an object specifying db/coll (as of MongoDB 4.4)
expectType<AggregationCursor<Document>>(builtCursor.out({ db: 'db', coll: 'collection' }));
// should error on other object shapes
expectError(builtCursor.out({ other: 'shape' }));
// should error on non-object, non-string values
expectError(builtCursor.out(1));