Mongodb 如何在Mongoose中设置别名

Mongodb 如何在Mongoose中设置别名,mongodb,mongoose,mongoose-schema,Mongodb,Mongoose,Mongoose Schema,为了减少mongoose中MongoDB的文档大小,我想使用alias特性。但是我不知道如何为位置设置它 const questionSchema = new Schema({ location: { country: { type: String }, province: { type: String }, town: { type: String }, }); const questionSchema=新模式({

为了减少mongoose中MongoDB的文档大小,我想使用alias特性。但是我不知道如何为位置设置它

const questionSchema = new Schema({
    location: {
        country:  { type: String },
        province: { type: String },
        town:     { type: String },
    });

const questionSchema=新模式({

l:{//alias:'location',我们可以在使用它们之后单独定义位置模式

const locationSchema = new Schema({
        country:  { type: String },
        province: { type: String },
        town:     { type: String },
    });

const questionSchema = new Schema({location:locationSchema});
试试这个形状

 const LocationSchema = new Schema({
        location: {
            country:  { type: String },

            //what it is content attribute withe type 

        }});
    const questionSchema = new Schema({
    location:LocationSchema 
    });
const locationSchema=新模式({
国家:{
类型:字符串
},
省:{
类型:字符串
},
城镇:{
类型:字符串
},
});
const questionSchema=新模式({
l:{
类型:locationSchema,
别名:“位置”
}

});
您可以在问题模式中使用后定义位置的单独模式I编辑问题。如何为此解决方案设置“位置”的别名?在这种情况下,
新模式({l:locationSchema})
,如何将“位置”设置为
l
对象的别名?
 const LocationSchema = new Schema({
        location: {
            country:  { type: String },

            //what it is content attribute withe type 

        }});
    const questionSchema = new Schema({
    location:LocationSchema 
    });