备忘--node连接mongodb
时间:2021-07-01 10:21:17
帮助过:3人阅读
=
express.Router()
const mongoose = require(‘mongoose‘
)
mongoose.connect(‘mongodb://localhost:27017/testdb‘, { useNewUrlParser:
true })
const PositionModel = mongoose.model(‘positions‘
, {
positionName: String,
})
const position =
new PositionModel({
positionName: ‘就安大略‘
})
router.post(‘/save‘, (req, res) =>
{
position.save().then((result) =>
{
console.log(result)
res.send(‘datas have saved mongodb‘
)
});
})
module.exports = router
# 4 再insomia中测试接口
# 5 在robo 3t可视化工具查看数据已经存入
备忘--node连接mongodb
标签:console span alt std const bsp log 图片 数据