我正在玩mongodb / node.js尝试使用失眠来测试我的数据库。当我发出POST请求时,返回对象数组,但它只包含对象id。奇怪的是,当我使用mongo手动添加数据时,在该实例中输入的所有数据都作为JSON正确返回,但是在失眠中添加时,只返回id。我错过了什么?这是我的邮寄路线:
router.post("/", function(req,res){
var car = req.body.car;
var newCar = new Car(car);
newCar.save(function(err, car){
if(err) return console.log(err);
else{
res.redirect(302, "/cars");
}
})
})
以下是失眠症的回复:
{
"cars": [
{
"_id": "5842322dbb7039837fdec0b7",
"car": "Ferrari",
"top_speed": "200"
},
{
"_id": "58423607bb7039837fdec0b8",
"car": "Ford",
"top_speed": "150"
},
{
"_id": "5842384b65039e33bb436ef2",
"__v": 0
},
{
"_id": "58423b2165039e33bb436ef3",
"__v": 0
},
{
"_id": "58423b3fa7cb093588dd2c47",
"__v": 0
},
{
"_id": "58423d8da7cb093588dd2c48",
"__v": 0
}
]
}
我的POST请求语法如下:
{
"car": "Ford",
"top_speed": "150"
}
和模型,如果它有帮助:
var mongoose = require('mongoose');
var carSchema = new mongoose.Schema({
"car": String,
"top_speed": String,
})
var Car = mongoose.model('Car', carSchema);
module.exports = Car;