Skip to content

Commit 37c1328

Browse files
emadumljhaywar
authored andcommitted
fix(NODE-3467): allow object type for aggregate out helper (#2971)
1 parent 37f6163 commit 37c1328

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/cursor/aggregation_cursor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class AggregationCursor<TSchema = Document> extends AbstractCursor<TSchem
121121
}
122122

123123
/** Add an out stage to the aggregation pipeline */
124-
out($out: string): this {
124+
out($out: { db: string; coll: string } | string): this {
125125
assertUninitialized(this);
126126
this[kPipeline].push({ $out });
127127
return this;

test/types/mongodb.test-d.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,11 @@ expectType<string | null>(await composedMap.next());
3737
expectType<string[]>(await composedMap.toArray());
3838

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

0 commit comments

Comments
 (0)