Node.js mongoose:MissingSchemaError:Schema没有';I don’我没有注册模特儿
我创建了一个pokedex并将这个pokemons表与它们的类型链接在一起,在浏览互联网时,我找到了在搜索中应用的.populate方法,但我不能 错误 (节点:10256)未经处理的PromisejectionWarning:MissingSchemaError:Schema尚未为模型“GenerationsPokemons”注册 口袋妖怪模型Node.js mongoose:MissingSchemaError:Schema没有';I don’我没有注册模特儿,node.js,mongodb,mongoose,nodes,Node.js,Mongodb,Mongoose,Nodes,我创建了一个pokedex并将这个pokemons表与它们的类型链接在一起,在浏览互联网时,我找到了在搜索中应用的.populate方法,但我不能 错误 (节点:10256)未经处理的PromisejectionWarning:MissingSchemaError:Schema尚未为模型“GenerationsPokemons”注册 口袋妖怪模型 const mongoose = require('../../database/index'); const Schema = mongoo
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;
MyServicePokemon.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;