My data model :
var UserDetail = new Schema({
username: String,
password: String
}, {
collection: 'userInfo'
});
var UserDetails = mongoose.model('userInfo', UserDetail);
This is my post method in the routes file
//POST
router.post( '/api/users', function( req, res ) {
var user = new UserDetails({
username: req.body.username,
password: req.body.password
});
console.log(req.body.username);
user.save( function( err ) {
if( !err ) {
console.log( 'created' );
return res.send( user );
} else {
console.log( err );
return res.send('ERROR');
}
});
});
My get api works perfect. The josn looks like this :
{"username":"exmpleUsername","password":"examplePassword","_id":"54091d9df8f00fb42055b6f8","__v":0}
But when I try to POST using POSTMAN, it doesn't add the username and password. It just adds new _id like this:
{"_id":"540e394f37706f701020cf19","__v":0}
Thanks in advance!
Please Check Your Schema Class whether username and password is private
var Schema = function(){
var self = this;
var username = ""; // mean private
self._id = ""; // mean public
};