我可以在邮递员中写入数据库但是当我在我的应用程序中发起帖子时,只存储生成的id。数据正在前端传递。
我的结构有问题吗?
模型/ resource.js
const mongoose = require("mongoose")
const Schema = mongoose.Schema,
model = mongoose.model.bind(mongoose)
const ResourceSchema = Schema({
first_name: String,
last_name: String,
email: String,
timezone: String
})
const Resource = model("Resource", ResourceSchema);
module.exports = Resource;
routs / resources.js
const express = require('express');
const router = express.Router();
const Resource = require('../models/resource.js')
router.get('/resources', (req, res) => {
Resource.find((err, resources) => {
if(err) throw err
res.render('resources', {title: 'Resources', resources: resources})
})
}).post('/resources', (req, res) => {
// const newResource = new Resource(req.body);
Resource.create(req.body, err => {
if (err) throw err
console.log("resources in mongodb" + res.json())
})
})
app.js
const resources = require('../routes/resources')
app.use(resources)