【发布时间】:2020-08-14 21:56:44
【问题描述】:
在MongoDB atlas 中发布数据时出错。
const express = require('express');
const router = express.Router();
const Persons = require('./PersonsSchema');
router.post('/',async(req,res)=>{
console.log(req.body.Name);
console.log(req.body.Age);
try{
const postPerson = await new Persons({
Name : req.body.Name,
Age : req.body.Age
})
const savePersons = await postPerson.save();
res.status(200).json(savePersons)
}
catch(err){
res.json({"err": err})
}
});
module.exports = router;
上面提到的是路由文件。
我的数据张贴在地图集中。但我收到一个错误 发布数据时邮递员中的 UnknownReplWriteConcern。
我的Schema 看起来像
const mongoose = require('mongoose');
const PersonSchema = new mongoose.Schema({ name: String },{ age: String }, {
writeConcern: {
w: 'majority',
j: true,
wtimeout: 1000
}
});
module.exports = mongoose.model('Persons',PersonSchema);
【问题讨论】:
标签: node.js mongodb express mongoose mongodb-atlas