gpt4 book ai didi

node.js - Mongoose findOne() 不是函数

转载 作者:行者123 更新时间:2023-12-04 08:27:57 26 4
gpt4 key购买 nike

gooModel.js
//用户模型

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

const GooSchema = new Schema(
{
goo_id: {
type: String,
required: true,
unique: true,
},
},
{ collection: 'goo_collection' }
);


module.exports = Goo = mongoose.model(
'goo',
GooSchema
);
auth_controller.js
//新用户
    const NewGoo = new Goo({
goo_id,
})
//功能
await NewGoo.findOne({ goo })}
我得到 findOne() 不是函数错误。我不知道我在哪里犯了错误。它在我的 mongo atlas 数据库上创建集合(但它是空的)。我在不同的工作 route 有完全相同的模型。我现在 super 无知。

最佳答案

我想你应该打电话findOne在模型本身上,而不是在 NewGoo 的实例/文档上指。所以尝试将其更改为:

await Goo.findOne({ goo })}

关于node.js - Mongoose findOne() 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65172605/

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