File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -1049,7 +1049,7 @@ Aggregate.prototype.exec = async function exec() {
1049
1049
const options = clone ( this . options || { } ) ;
1050
1050
let result ;
1051
1051
try {
1052
- const cursor = collection . aggregate ( this . _pipeline , options ) ;
1052
+ const cursor = await collection . aggregate ( this . _pipeline , options ) ;
1053
1053
result = await cursor . toArray ( ) ;
1054
1054
} catch ( error ) {
1055
1055
await new Promise ( ( resolve , reject ) => {
Original file line number Diff line number Diff line change @@ -1242,4 +1242,22 @@ describe('aggregate: ', function() {
1242
1242
} ) ;
1243
1243
} ) ;
1244
1244
1245
+ it ( 'should not throw error if database connection has not been established (gh-13125)' , async function ( ) {
1246
+ const m = new mongoose . Mongoose ( ) ;
1247
+ const mySchema = new Schema ( { test : String } ) ;
1248
+ const M = m . model ( 'Test' , mySchema ) ;
1249
+
1250
+ const aggregate = M . aggregate ( ) ;
1251
+ aggregate . match ( { $match : { foo : 'bar' } } ) ;
1252
+
1253
+ const p = aggregate . exec ( ) ;
1254
+
1255
+ await new Promise ( resolve => setTimeout ( resolve , 0 ) ) ;
1256
+ await m . connect ( start . uri ) ;
1257
+
1258
+ assert . doesNotThrow ( async function ( ) {
1259
+ await p ;
1260
+ } ) ;
1261
+ await m . disconnect ( ) ;
1262
+ } ) ;
1245
1263
} ) ;
You can’t perform that action at this time.
0 commit comments