File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -2037,11 +2037,9 @@ Schema.prototype.index = function(fields, options) {
2037
2037
}
2038
2038
for ( const key in fields ) {
2039
2039
if ( this . aliases [ key ] ) {
2040
- fields [ this . aliases [ key ] ] = fields [ key ] ;
2041
- delete fields [ key ] ;
2040
+ fields = utils . renameObjKey ( fields , key , this . aliases [ key ] ) ;
2042
2041
}
2043
2042
}
2044
-
2045
2043
for ( const field of Object . keys ( fields ) ) {
2046
2044
if ( fields [ field ] === 'ascending' || fields [ field ] === 'asc' ) {
2047
2045
fields [ field ] = 1 ;
Original file line number Diff line number Diff line change @@ -964,6 +964,29 @@ exports.each = function(arr, fn) {
964
964
}
965
965
} ;
966
966
967
+ /**
968
+ * Rename an object key, while preserving its position in the object
969
+ *
970
+ * @param {Object } oldObj
971
+ * @param {String|Number } oldKey
972
+ * @param {String|Number } newKey
973
+ * @api private
974
+ */
975
+ exports . renameObjKey = function ( oldObj , oldKey , newKey ) {
976
+ const keys = Object . keys ( oldObj ) ;
977
+ return keys . reduce (
978
+ ( acc , val ) => {
979
+ if ( val === oldKey ) {
980
+ acc [ newKey ] = oldObj [ oldKey ] ;
981
+ } else {
982
+ acc [ val ] = oldObj [ val ] ;
983
+ }
984
+ return acc ;
985
+ } ,
986
+ { }
987
+ ) ;
988
+ } ;
989
+
967
990
/*!
968
991
* ignore
969
992
*/
You can’t perform that action at this time.
0 commit comments