gpt4 book ai didi

javascript - TypeError : Post. create 不是 mongodb 的函数

转载 作者:行者123 更新时间:2023-12-03 00:01:14 24 4
gpt4 key购买 nike

test.js 文件包含 .create 函数,该函数在运行时显示类型错误。我尝试过插入函数保存函数,但它根本没有将其识别为函数。我无法找出创建函数中的类型错误是什么。

test.js文件

const mongoose = require('mongoose')
const Post = ('/database/models/Post')

mongoose.connect('mongodb://localhost/nodejs-test-blog')

// Post.find({}, (error, posts) => {
// console.log(error, posts)
// })

Post.create({
title: 'My second blog post',
description: 'Second Blog post description',
content: 'Second Lorem ipsum content.'
}, (error, post) => {
console.log(error, post)
})

Post.js文件

const mongoose = require('mongoose')
///

const PostSchema = new mongoose.Schema({
title: String,
description: String,
content: String
})

const Post = mongoose.model('Post', PostSchema)

module.exports = Post

最佳答案

使用 mongodb 定义模式路径

require('./database/models/Post')

关于javascript - TypeError : Post. create 不是 mongodb 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55168481/

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