node.js - 如何构建在猫鼬中工作的嵌套模式?
问题描述
我想在 NodeJs 上构建一个应用程序,它将分析我将输入的一些信息。目前我可以为一个模式编码。但我不能嵌套。任何人都可以帮助我解决这个问题。提前致谢。
var ProvinceSchema = new mongoose.Schema({ city: String });
在每个城市里,我想把温度,人口。
解决方案
您可以为城市创建一个模式并添加一些必需的字段,例如城市名称、温度、人口等,如下所示。
const cityDetailsSchema = new Schema({
cityname: {
type: String,
max: 24,
required: [true, 'Please enter cityname']
},
temparature: {
type: String,
required: true
},
populations: {
type: Number,
required: true
},
nested: cityDetailsNestedSchema
// you can create more fields like as above.
});
const cityDetailsNestedSchema = new Schema({
keyName: {
type: String,
lowercase: true,
trim: true
}
})
推荐阅读
- javascript - 溢出:隐藏在 iPad iOS 11 上不起作用
- ruby-on-rails - Rails 固定装置和命名空间模型 - ActiveRecord::Fixture::FixtureError
- angular - Angular 2+ 中的复杂和多种变换样式
- bash - tr 命令:| 的奇怪行为 和 \
- django - 提高 Django 登录安全性和密码强度
- python - 取消设置或关闭某些属性的当前模块
- c# - 无法让控制台日志记录在 .net core 2.0 中工作
- java - 检查所有 ListView CheckBoxes 时如何触发 JavaFX 事件?
- ruby - Google Analytics API ruby 客户端 - 多个指标
- google-analytics - Google Analytics 事件 - 日期范围值