@@ -2222,6 +2222,7 @@ function _castArrayFilters(query) {
2222
2222
* @api private
2223
2223
*/
2224
2224
Query . prototype . _find = async function _find ( ) {
2225
+ this . _applyTranslateAliases ( ) ;
2225
2226
this . _castConditions ( ) ;
2226
2227
2227
2228
if ( this . error ( ) != null ) {
@@ -2244,8 +2245,6 @@ Query.prototype._find = async function _find() {
2244
2245
2245
2246
const options = this . _optionsForExec ( ) ;
2246
2247
2247
- this . _applyTranslateAliases ( options ) ;
2248
-
2249
2248
const filter = this . _conditions ;
2250
2249
const fields = options . projection ;
2251
2250
@@ -2510,6 +2509,7 @@ Query.prototype._completeMany = async function _completeMany(docs, fields, userP
2510
2509
*/
2511
2510
2512
2511
Query . prototype . _findOne = async function _findOne ( ) {
2512
+ this . _applyTranslateAliases ( ) ;
2513
2513
this . _castConditions ( ) ;
2514
2514
2515
2515
if ( this . error ( ) ) {
@@ -2522,8 +2522,6 @@ Query.prototype._findOne = async function _findOne() {
2522
2522
2523
2523
const options = this . _optionsForExec ( ) ;
2524
2524
2525
- this . _applyTranslateAliases ( options ) ;
2526
-
2527
2525
// don't pass in the conditions because we already merged them in
2528
2526
const doc = await this . mongooseCollection . findOne ( this . _conditions , options ) ;
2529
2527
return new Promise ( ( resolve , reject ) => {
@@ -2604,6 +2602,8 @@ Query.prototype.findOne = function(conditions, projection, options) {
2604
2602
*/
2605
2603
2606
2604
Query . prototype . _countDocuments = async function _countDocuments ( ) {
2605
+ this . _applyTranslateAliases ( ) ;
2606
+
2607
2607
try {
2608
2608
this . cast ( this . model ) ;
2609
2609
} catch ( err ) {
@@ -2619,8 +2619,6 @@ Query.prototype._countDocuments = async function _countDocuments() {
2619
2619
2620
2620
const options = this . _optionsForExec ( ) ;
2621
2621
2622
- this . _applyTranslateAliases ( options ) ;
2623
-
2624
2622
const conds = this . _conditions ;
2625
2623
2626
2624
return this . mongooseCollection . countDocuments ( conds , options ) ;
@@ -2631,7 +2629,7 @@ Query.prototype._countDocuments = async function _countDocuments() {
2631
2629
* on the following query properties: filter, projection, update, distinct.
2632
2630
*/
2633
2631
2634
- Query . prototype . _applyTranslateAliases = function _applyTranslateAliases ( options ) {
2632
+ Query . prototype . _applyTranslateAliases = function _applyTranslateAliases ( ) {
2635
2633
let applyTranslateAliases = false ;
2636
2634
if ( 'translateAliases' in this . _mongooseOptions ) {
2637
2635
applyTranslateAliases = this . _mongooseOptions . translateAliases ;
@@ -2646,7 +2644,7 @@ Query.prototype._applyTranslateAliases = function _applyTranslateAliases(options
2646
2644
2647
2645
if ( this . model ?. schema ?. aliases && Object . keys ( this . model . schema . aliases ) . length > 0 ) {
2648
2646
this . model . translateAliases ( this . _conditions , true ) ;
2649
- this . model . translateAliases ( options . projection , true ) ;
2647
+ this . model . translateAliases ( this . _fields , true ) ;
2650
2648
this . model . translateAliases ( this . _update , true ) ;
2651
2649
if ( this . _distinct != null && this . model . schema . aliases [ this . _distinct ] != null ) {
2652
2650
this . _distinct = this . model . schema . aliases [ this . _distinct ] ;
@@ -2777,6 +2775,7 @@ Query.prototype.countDocuments = function(conditions, options) {
2777
2775
*/
2778
2776
2779
2777
Query . prototype . __distinct = async function __distinct ( ) {
2778
+ this . _applyTranslateAliases ( ) ;
2780
2779
this . _castConditions ( ) ;
2781
2780
2782
2781
if ( this . error ( ) ) {
@@ -2787,7 +2786,6 @@ Query.prototype.__distinct = async function __distinct() {
2787
2786
applyGlobalDiskUse ( this . options , this . model . db . options , this . model . base . options ) ;
2788
2787
2789
2788
const options = this . _optionsForExec ( ) ;
2790
- this . _applyTranslateAliases ( options ) ;
2791
2789
2792
2790
return this . mongooseCollection .
2793
2791
distinct ( this . _distinct , this . _conditions , options ) ;
@@ -3006,14 +3004,14 @@ Query.prototype.deleteOne = function deleteOne(filter, options) {
3006
3004
*/
3007
3005
3008
3006
Query . prototype . _deleteOne = async function _deleteOne ( ) {
3007
+ this . _applyTranslateAliases ( ) ;
3009
3008
this . _castConditions ( ) ;
3010
3009
3011
3010
if ( this . error ( ) != null ) {
3012
3011
throw this . error ( ) ;
3013
3012
}
3014
3013
3015
3014
const options = this . _optionsForExec ( ) ;
3016
- this . _applyTranslateAliases ( options ) ;
3017
3015
3018
3016
return this . mongooseCollection . deleteOne ( this . _conditions , options ) ;
3019
3017
} ;
@@ -3080,14 +3078,14 @@ Query.prototype.deleteMany = function(filter, options) {
3080
3078
*/
3081
3079
3082
3080
Query . prototype . _deleteMany = async function _deleteMany ( ) {
3081
+ this . _applyTranslateAliases ( ) ;
3083
3082
this . _castConditions ( ) ;
3084
3083
3085
3084
if ( this . error ( ) != null ) {
3086
3085
throw this . error ( ) ;
3087
3086
}
3088
3087
3089
3088
const options = this . _optionsForExec ( ) ;
3090
- this . _applyTranslateAliases ( options ) ;
3091
3089
3092
3090
return this . mongooseCollection . deleteMany ( this . _conditions , options ) ;
3093
3091
} ;
@@ -3277,6 +3275,7 @@ Query.prototype.findOneAndUpdate = function(filter, doc, options) {
3277
3275
*/
3278
3276
3279
3277
Query . prototype . _findOneAndUpdate = async function _findOneAndUpdate ( ) {
3278
+ this . _applyTranslateAliases ( ) ;
3280
3279
this . _castConditions ( ) ;
3281
3280
3282
3281
_castArrayFilters ( this ) ;
@@ -3293,7 +3292,6 @@ Query.prototype._findOneAndUpdate = async function _findOneAndUpdate() {
3293
3292
}
3294
3293
const options = this . _optionsForExec ( this . model ) ;
3295
3294
convertNewToReturnDocument ( options ) ;
3296
- this . _applyTranslateAliases ( options ) ;
3297
3295
3298
3296
this . _update = this . _castUpdate ( this . _update ) ;
3299
3297
@@ -3418,6 +3416,7 @@ Query.prototype.findOneAndDelete = function(filter, options) {
3418
3416
* @api private
3419
3417
*/
3420
3418
Query . prototype . _findOneAndDelete = async function _findOneAndDelete ( ) {
3419
+ this . _applyTranslateAliases ( ) ;
3421
3420
this . _castConditions ( ) ;
3422
3421
3423
3422
if ( this . error ( ) != null ) {
@@ -3428,7 +3427,6 @@ Query.prototype._findOneAndDelete = async function _findOneAndDelete() {
3428
3427
3429
3428
const filter = this . _conditions ;
3430
3429
const options = this . _optionsForExec ( this . model ) ;
3431
- this . _applyTranslateAliases ( options ) ;
3432
3430
3433
3431
let res = await this . mongooseCollection . findOneAndDelete ( filter , options ) ;
3434
3432
for ( const fn of this . _transforms ) {
@@ -3542,6 +3540,7 @@ Query.prototype.findOneAndReplace = function(filter, replacement, options) {
3542
3540
* @api private
3543
3541
*/
3544
3542
Query . prototype . _findOneAndReplace = async function _findOneAndReplace ( ) {
3543
+ this . _applyTranslateAliases ( ) ;
3545
3544
this . _castConditions ( ) ;
3546
3545
if ( this . error ( ) != null ) {
3547
3546
throw this . error ( ) ;
@@ -3554,7 +3553,6 @@ Query.prototype._findOneAndReplace = async function _findOneAndReplace() {
3554
3553
3555
3554
const filter = this . _conditions ;
3556
3555
const options = this . _optionsForExec ( ) ;
3557
- this . _applyTranslateAliases ( options ) ;
3558
3556
convertNewToReturnDocument ( options ) ;
3559
3557
3560
3558
const includeResultMetadata = this . options . includeResultMetadata ;
@@ -3749,6 +3747,8 @@ Query.prototype._mergeUpdate = function(doc) {
3749
3747
*/
3750
3748
3751
3749
async function _updateThunk ( op ) {
3750
+ this . _applyTranslateAliases ( ) ;
3751
+
3752
3752
this . _castConditions ( ) ;
3753
3753
3754
3754
_castArrayFilters ( this ) ;
@@ -3759,7 +3759,6 @@ async function _updateThunk(op) {
3759
3759
3760
3760
const castedQuery = this . _conditions ;
3761
3761
const options = this . _optionsForExec ( this . model ) ;
3762
- this . _applyTranslateAliases ( options ) ;
3763
3762
3764
3763
this . _update = clone ( this . _update , options ) ;
3765
3764
const isOverwriting = op === 'replaceOne' ;
0 commit comments