'how to custom props in mongoose in select like projection in populated prop

we can use select like in projection but we can't use it same in referenced prop

The model is like this

const AddressSchema = new Schema({
street: String
country: String
})

const UserSchema = new Schema({
name: String,
surname: String,
address: {type: mongoose.Schema.Types.ObjectId, ref:'Address'}
})

This is a simple sentence that works

const User = await User.find().select({
'fullName':{$concat: ['$name', ' ', '$surname']}
})

Now we want to use it to populate

const User = await User.find()
  .populate({
    path: 'address',
    select: ({
      'specialCountry': {'address': '$_id'}
    })
  })

why can't create a special prop?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source