【问题标题】:MongoDB error when i run this code it gives me that error运行此代码时出现 MongoDB 错误,它给了我该错误
【发布时间】:2020-11-09 22:54:19
【问题描述】:

我的编辑器中的错误:

D:\MEAN\app\models\user.js:1

const Schema = mongoose.Schema;  

                   

TypeError:无法读取未定义的属性“架构” 在对象。 (D:\MEAN\app\models\user.js:1:25) 在 Module._compile (node:interna

const Schema = mongoose.Schema;
var mongoose = require("mongoose");
// const { Schema } = mongoose.Schema;

var UserSchema = new Schema({
  username: { type: String, lowercase: true, required: true, unique: true },
  email: { type: String, lowercase: true, required: true, unique: true },
  password: { type: String, required: true },
});
module.exports = mongoose.model("User", UserSchema);

【问题讨论】:

    标签: javascript mongodb mongoose


    【解决方案1】:

    这样试试

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

    如果没有,请确保已安装 mongoose

    npm install mongoose --save
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      • 2018-12-09
      • 2017-05-16
      • 2022-11-13
      • 2019-01-26
      • 2021-12-24
      • 1970-01-01
      相关资源
      最近更新 更多