我创建了一个 pokedex 并将这个 pokemons 表与它们的类型联系起来,在查阅互联网时我发现 .populate 方法可以应用于搜索,但我不能
错误
<块引用>(节点:10256)未处理的PromiseRejectionWarning: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;
我的 servicepokemon.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;