【问题标题】:^ TypeError: Invalid schema configuration: `U` is not a valid type at path `0`^ TypeError:无效的架构配置:`U` 不是路径 `0` 处的有效类型
【发布时间】:2021-03-24 20:07:29
【问题描述】:
const userSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true,
        unique: true
    },
    password: {
        type: String,
        required: true
    },
    avatar: {
        type: String
    },
});
    
module.exports= user = mongoose.Schema('user',userSchema);

【问题讨论】:

  • 请帮帮我
  • 请澄清您的具体问题或添加其他详细信息以准确突出您的需要。正如目前所写的那样,很难准确地说出你在问什么。请参阅如何提问页面以帮助澄清此问题:stackoverflow.com/help/how-to-ask
  • module.exports= user = mongoose.Schema('user',userSchema); 此行无效。 user 部分来自哪里?
  • 另外,您正在将 Mongoose 架构分配给另一个 Mongoose 架构。应该是mongoose.model('user',userSchema)

标签: node.js express mongoose mongoose-schema


【解决方案1】:

您使用mongoose.Schema() 完全错误。您应该使用mongoose.Model('user', userSchema) 创建用户模型,请参阅mongoose.Model()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 2021-07-23
    • 2020-03-26
    • 2019-08-16
    • 2023-02-09
    • 2022-07-28
    • 1970-01-01
    相关资源
    最近更新 更多