'Mongoose - Whole object select false

I have a mongoose-model declaration which contain a object with a bunch of individual fields. I don't want each field to be returned by default and so set the "select: false" property for each individual field in the object of my mongoose-model.

const userSchema = new Schema({
    location: {
        city: { type: String, select: false },
        country: { type: String, select: false },
        postcode: { type: String, select: false },
        street: { type: String, select: false }
    }
})

Instead of having the .select-property for each property of my location-obj, I want to set the "select: false" for the whole location-object and so either receive the entire nested object when using .select("+location") or none of the properties by default instead of having it like yet where i need to select each field individually like .select("+location.city +location.country +location.postcode")



Sources

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

Source: Stack Overflow

Solution Source