我正在尝试创建一个模型“Product”,但是当我在控制器中通过名称“Product”访问该模型时,它会返回此错误。
型号产品
const mongoose = require('mongoose');
const ProductSchema = new mongoose.Schema({
title: {
type: String,
required: true
},
description: {
type: String,
required: true
},
url: {
type: String,
required: true
},
createdAt: {
type: Date,
default: Date.now()
}
});
mongoose.model('Product', ProductSchema);
产品控制器
const mongoose = require('mongoose');
const Product = mongoose.model('Product');
module.exports = {
async index(req, res) {
const products = await Product.find();
return res.json(products);
}
}
皈依舞
相关分类