@@ -1075,4 +1075,44 @@ describe('document.populate', function() {
10751075 assert . deepStrictEqual ( codeUser . extras [ 0 ] . config . paymentConfiguration . paymentMethods [ 0 ] . _id , code . _id ) ;
10761076 assert . strictEqual ( codeUser . extras [ 0 ] . config . paymentConfiguration . paymentMethods [ 0 ] . code , 'test code' ) ;
10771077 } ) ;
1078+
1079+ it ( 'supports populate with ordered option (gh-15231)' , async function ( ) {
1080+ const docSchema = new Schema ( {
1081+ refA : { type : Schema . Types . ObjectId , ref : 'Test1' } ,
1082+ refB : { type : Schema . Types . ObjectId , ref : 'Test2' } ,
1083+ refC : { type : Schema . Types . ObjectId , ref : 'Test3' }
1084+ } ) ;
1085+
1086+ const doc1Schema = new Schema ( { name : String } ) ;
1087+ const doc2Schema = new Schema ( { title : String } ) ;
1088+ const doc3Schema = new Schema ( { content : String } ) ;
1089+
1090+ const Doc = db . model ( 'Test' , docSchema ) ;
1091+ const Doc1 = db . model ( 'Test1' , doc1Schema ) ;
1092+ const Doc2 = db . model ( 'Test2' , doc2Schema ) ;
1093+ const Doc3 = db . model ( 'Test3' , doc3Schema ) ;
1094+
1095+ const doc1 = await Doc1 . create ( { name : 'test 1' } ) ;
1096+ const doc2 = await Doc2 . create ( { title : 'test 2' } ) ;
1097+ const doc3 = await Doc3 . create ( { content : 'test 3' } ) ;
1098+
1099+ const docD = await Doc . create ( {
1100+ refA : doc1 . _id ,
1101+ refB : doc2 . _id ,
1102+ refC : doc3 . _id
1103+ } ) ;
1104+
1105+ await docD . populate ( {
1106+ path : [ 'refA' , 'refB' , 'refC' ] ,
1107+ ordered : true
1108+ } ) ;
1109+
1110+ assert . ok ( docD . populated ( 'refA' ) ) ;
1111+ assert . ok ( docD . populated ( 'refB' ) ) ;
1112+ assert . ok ( docD . populated ( 'refC' ) ) ;
1113+
1114+ assert . equal ( docD . refA . name , 'test 1' ) ;
1115+ assert . equal ( docD . refB . title , 'test 2' ) ;
1116+ assert . equal ( docD . refC . content , 'test 3' ) ;
1117+ } ) ;
10781118} ) ;
0 commit comments