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 @@ -1526,7 +1526,12 @@ Model.diffIndexes = async function diffIndexes() {
1526
1526
1527
1527
const model = this ;
1528
1528
1529
- let dbIndexes = await model . listIndexes ( ) ;
1529
+ let dbIndexes = await model . listIndexes ( ) . catch ( err => {
1530
+ if ( err . codeName == 'NamespaceNotFound' ) {
1531
+ return undefined ;
1532
+ }
1533
+ throw err ;
1534
+ } ) ;
1530
1535
if ( dbIndexes === undefined ) {
1531
1536
dbIndexes = [ ] ;
1532
1537
}
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