如何从mongodb中的嵌套模式中获取特定模式?

时间:2019-04-02 09:27:51

标签: mongodb

我只需要从该国家/地区集合中获取状态架构。 如何只采用状态模式?

var mongoose = require('mongoose');

var iterationsSchema = mongoose.Schema({
    name : String,
    effectiveFrom : {type : Date, default : new Date()},
    active : {type: Boolean, default:true}
});

var citySchema = mongoose.Schema({
    cityName:String,
    iterations : [iterationsSchema],
    active:{type:Boolean,default:true}
});

var StateSchema = mongoose.Schema({
    stateName:String,
    iterations : [iterationsSchema],
    cities:[citySchema],
    active:{type:Boolean,default:true}
});

var CountrySchema = mongoose.Schema({
    countryName:String,
    iterations : [iterationsSchema],
    states:[StateSchema],
    active:{type:Boolean,default:true}
});

var Country = mongoose.model('Country',CountrySchema);
module.exports = Country;

0 个答案:

没有答案