gpt4 book ai didi

node.js - 无效的架构配置 : `model` is not a valid type within the array `characters`

转载 作者:行者123 更新时间:2023-12-03 12:16:17 28 4
gpt4 key购买 nike

我正在尝试创建一个架构子文档,但出现上面列出的错误,
有问题的模式看起来像这样
架构引发问题

const mongoose = require('mongoose');
const Schema = mongoose.Schema

const CharacterSchema = new Schema();
CharacterSchema.add({
name: {
type: String,
required: true
},
title: {
type: String
},
charcterClass: { // will be limited in form creation
type: String
},
level: {
type: Number
}
});

const Charcter = mongoose.model('User', CharacterSchema);
module.exports = Charcter;

模式调用 上方的模式
const mongoose = require ('mongoose');
const Schema = mongoose.Schema;
const {CharacterSchema} = require(__dirname +'/CharacterModel.js');

const UserSchema = new Schema()
UserSchema.add({
name: {
type: String,
required: true
} ,
characters: [CharacterSchema]
});

const User = mongoose.model('Character', UserSchema);
module.exports = User;

最佳答案

尝试以这种方式进行导入
const {CharacterSchema} = require(__dirname +'/CharacterModel.js').schema;
最后添加 .schema

这篇文章与您的问题有关,您将在那里看到解释。

Embedding schemas is giving error

关于node.js - 无效的架构配置 : `model` is not a valid type within the array `characters` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59131840/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com