gpt4 book ai didi

node.js - TypeError : this. add 不是 Node js应用程序中的函数

转载 作者:行者123 更新时间:2023-12-03 01:45:46 26 4
gpt4 key购买 nike

我有 mongoose 版本 2.6,mongodb 版本是 2.2 我正在尝试创建 CRUD 应用程序,在其中定义模式。通过在我的项目中添加架构。我收到此错误:“TypeError:this.add 不是函数”

以下是我的代码:

const mongoose = require('mongoose');

let userSchema = mongoose.Schema({
name: { type: String },
email: { type: String },
password: { type: String },
forgotToken: { type: String }
});

module.exports = mongoose.model('user', userSchema);

我不知道我的代码有什么问题。从代码模型创建应该没有任何错误。请帮帮我。

最佳答案

您忘记了通过不在模式对象前面添加 new 关键字来创建模式对象的新实例。

const mongoose = require('mongoose');

let userSchema = new mongoose.Schema({
name: { type: String },
email: { type: String },
password: { type: String },
forgotToken: { type: String }
});

module.exports = mongoose.model('user', userSchema);

关于node.js - TypeError : this. add 不是 Node js应用程序中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56016183/

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