сотрудник. js
const mongoose = require('mongoose');
var Employee = mongoose.model('Employee', {
name: { type: String },
position: { type: String },
office: { type: String },
salary: { type: Number }
});
module.exports = { Employee };
employeeController. js
const express = require('express');
var router = express.Router();
var { Employee } = require('../models/employee');
router.get('/', (req, res) => {
Employee.find((err, docs) =>{
if (!err) {res.send(docs);}
else {console.log('Error in Retriving Employees: '+ JSON.stringify(err, undefined, 2));}
});
});
router.post('/', (req, res) => {
var emp = new Employee({
name: req.body.name,
position: req.body.position,
office: req.body.office,
salary: req.body.salary,
});
emp.save((err, doc) => {
if(!err) {res.send(doc); }
else {console.log('Error in employee save:' + JSON.stringify(err, undefined,
2));}
});
});
module.exports = router;
В почтальоне добавляю :
{
"name":"Anida Mujezin",
"position":"Full stack developer",
"office":"Sarajevo",
"salary":3000
}
Ошибка: Ошибка при сохранении сотрудника: {"driver": true, "name": "MongoError", "index": 0, "code" : 13297}
и не удалось получить ответ в почтальоне