Skip to content

Commit

Permalink
fix(NODE-3467): allow object type for aggregate out helper (#2971)
Browse files Browse the repository at this point in the history
  • Loading branch information
emadum authored Sep 3, 2021
1 parent a299a0b commit cd603e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cursor/aggregation_cursor.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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));

0 comments on commit cd603e8

Please sign in to comment.