File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1516,7 +1516,12 @@ Model.diffIndexes = async function diffIndexes() {
1516
1516
1517
1517
const model = this ;
1518
1518
1519
- let dbIndexes = await model . listIndexes ( ) ;
1519
+ let dbIndexes = await model . listIndexes ( ) . catch ( err => {
1520
+ if ( err . codeName == 'NamespaceNotFound' ) {
1521
+ return undefined ;
1522
+ }
1523
+ throw err ;
1524
+ } ) ;
1520
1525
if ( dbIndexes === undefined ) {
1521
1526
dbIndexes = [ ] ;
1522
1527
}
Original file line number Diff line number Diff line change @@ -714,5 +714,15 @@ describe('model', function() {
714
714
assert . deepStrictEqual ( result . toDrop , [ 'age_1' , 'weight_1' ] ) ;
715
715
assert . deepStrictEqual ( result . toCreate , [ { password : 1 } , { email : 1 } ] ) ;
716
716
} ) ;
717
+
718
+ it ( 'running diffIndexes with a non-existent collection should not throw an error (gh-14010)' , async function ( ) {
719
+ const testSchema = new mongoose . Schema ( {
720
+ name : String
721
+ } ) ;
722
+
723
+ const Test = db . model ( 'gh14010' , testSchema ) ;
724
+ const res = await Test . diffIndexes ( ) ;
725
+ assert . ok ( res ) ;
726
+ } ) ;
717
727
} ) ;
718
728
} ) ;
You can’t perform that action at this time.
0 commit comments