@@ -650,6 +650,72 @@ describe('model', function() {
650
650
} ) ;
651
651
} ) ;
652
652
653
+ it ( 'should not re-create a compound text index that involves non-text indexes, using syncIndexes (gh-13136)' , function ( done ) {
654
+ const Test = new Schema ( {
655
+ title : {
656
+ type : String
657
+ } ,
658
+ description : {
659
+ type : String
660
+ } ,
661
+ age : {
662
+ type : Number
663
+ }
664
+ } , {
665
+ autoIndex : false
666
+ } ) ;
667
+
668
+ Test . index ( {
669
+ title : 'text' ,
670
+ description : 'text' ,
671
+ age : 1
672
+ } ) ;
673
+
674
+ const TestModel = db . model ( 'Test' , Test ) ;
675
+ TestModel . syncIndexes ( ) . then ( ( results1 ) => {
676
+ assert . deepEqual ( results1 , [ ] ) ;
677
+ // second call to syncIndexes should return an empty array, representing 0 deleted indexes
678
+ TestModel . syncIndexes ( ) . then ( ( results2 ) => {
679
+ assert . deepEqual ( results2 , [ ] ) ;
680
+ done ( ) ;
681
+ } ) ;
682
+ } ) ;
683
+ } ) ;
684
+
685
+ it ( 'should not find a diff when calling diffIndexes after syncIndexes involving a text and non-text compound index (gh-13136)' , function ( done ) {
686
+ const Test = new Schema ( {
687
+ title : {
688
+ type : String
689
+ } ,
690
+ description : {
691
+ type : String
692
+ } ,
693
+ age : {
694
+ type : Number
695
+ }
696
+ } , {
697
+ autoIndex : false
698
+ } ) ;
699
+
700
+ Test . index ( {
701
+ title : 'text' ,
702
+ description : 'text' ,
703
+ age : 1
704
+ } ) ;
705
+
706
+ const TestModel = db . model ( 'Test' , Test ) ;
707
+
708
+ TestModel . diffIndexes ( ) . then ( ( diff ) => {
709
+ assert . deepEqual ( diff , { toCreate : [ { age : 1 , title : 'text' , description : 'text' } ] , toDrop : [ ] } ) ;
710
+ TestModel . syncIndexes ( ) . then ( ( ) => {
711
+ TestModel . diffIndexes ( ) . then ( ( diff2 ) => {
712
+ assert . deepEqual ( diff2 , { toCreate : [ ] , toDrop : [ ] } ) ;
713
+ done ( ) ;
714
+ } ) ;
715
+ } ) ;
716
+ } ) ;
717
+ } ) ;
718
+
653
719
it ( 'cleanIndexes (gh-6676)' , function ( ) {
654
720
return co ( function * ( ) {
655
721
let M = db . model ( 'Test' , new Schema ( {
0 commit comments