when ever i make a post request it returns only the created date and the objectID
当我发出发布请求时,它仅返回创建的日期和objectID 每当我发出发布请求时,它仅返回创建的日期和objectID 每当我发出发布请求时,它仅返回创建的日期和objectID
i tried testing it with postman but it was the same thing
//this is the controller for creating a new room
exports.create_a_room = function(req, res) {
let new_room = new Room(req.body);
new_room.save(function(err, task) {
if (err) res.send(err);//testing for errors
res.json(task);
});
};
//this is the schema for the Rest api.the created date is the the only one working
var RoomSchema = new Schema({
full_name: {//for full name
type: String,
Required: 'Enter first name'
},
time: {//for time
type: String,
Required: 'Enter checkout'
},
people: {//for people
type: Number,
Required: 'Enter people'
},
kids: {for kids
type: Number,
Required: 'Enter kids'
},
room_type: {//for room types
type: String,
Required: 'Enter room type'
},
room_number: {//for room number
type: Number,
Required: 'Enter room Number'
},
Created_date: {for created date.this is the only part of the schema that is actually working
type: Date,
default: Date.now
},
});
it just returns the created date and the objectID generated by mongodb
答案 0 :(得分:0)
您在MongoDB中使用Mongoose吗?因为您似乎架构不好。将所有行替换为“ Required:...”,例如:
Required: 'Enter first name'
具有:
required: true
(请注意大小写-首字母在“必填”中小写)
在此处查看更多信息: https://mongoosejs.com/docs/api.html#schematype_SchemaType-required