node.js - 猫鼬:MissingSchemaError:模式尚未注册模型
问题描述
我创建了一个 pokedex 并将这个 pokemons 表与其类型相关联,在查阅互联网时,我发现 .populate 方法可以应用于搜索,但我不能
呃
(节点:10256)UnhandledPromiseRejectionWarning:MissingSchemaError:尚未为模型“GenerationsPokemons”注册模式。
模型口袋妖怪
const mongoose = require('../../database/index');
const Schema = mongoose.Schema
const PokemonSchema = new mongoose.Schema({
name: {
type: String,
require: true
},
pokedexNumber: {
name: Number,
},
image: {
type: String,
require: false
},
generation: {
type: Schema.Types.ObjectId,
ref: "GenerationsPokemons",
},
evolutionStage: {
type: Schema.Types.ObjectId,
ref: "EvolutionStagePokemon"
},
typeone: {
type: Schema.Types.ObjectId,
ref: "TypesPokemon",
require: true
},
typetwo: {
type: Schema.Types.ObjectId,
ref: "TypesPokemon",
require: false
},
weatherOne: {
type: Schema.Types.ObjectId,
ref: "WheaterPokemon",
require: true
},
weatherTwo: {
type: Schema.Types.ObjectId,
ref: "WheaterPokemon",
require: false
},
attack: {
type: Number,
require: true,
},
defense: {
type: Number,
require: true,
},
stamina: {
type: Number,
require: true,
},
legendary: {
type: Schema.Types.ObjectId,
ref: "LegendarysPokemons",
},
max_cp: {
type: Number,
require: true,
},
cp:{
type: Number,
require: true,
},
createdAt: {
type: Date,
default: Date.now,
select: false,
}
})
const Pokemons = mongoose.model('Pokemons', PokemonSchema);
module.exports = Pokemons;
我的服务pokemon.js
async show(name, next) {
const pokemon = await Pokemons.find({name: name}).populate('generation')
if (!pokemon)
return next (Errors.NotFoundException('Pokemon not found'))
return pokemon
}
我这一代口袋妖怪
const mongoose = require('../../database/index');
const Schema = mongoose.Schema
const GenerationsPokemonsSchema = new mongoose.Schema({
generation: {
type: String,
require: true
},
createdAt: {
type: Date,
default: Date.now,
select: false,
}
})
const GenerationsPokemons = mongoose.model('GenerationsPokemons', GenerationsPokemonsSchema);
module.exports = GenerationsPokemons;
解决方案
推荐阅读
- xml - 需要在 xml 文件中编辑节点的属性值
- python - 在熊猫数据框中循环时删除一行
- c++ - C ++ 14制作自定义迭代器,它将按2并返回修改后的数据
- scala - 如何将一个数据集的列(也包括多列)中的值映射到另一个数据集
- php - Codeigniter:如何使用ajax修复分页链接,单击时不更新
- ms-access - 如何保持对子表单上选定记录的关注?
- python - 如何从预训练模型中删除最后一层。我试过 model.layers.pop() 但它不工作
- c# - 如何从 JObject 中获取一些特定值
- python - 将 Elmo 与 tf.Keras 一起使用会引发 ValueError:无法将字符串转换为浮点数
- groovy - SoapUI 启用测试步骤列表 (Groovy)