0

我的数据模型:

var UserDetail = new Schema({
      username: String,
      password: String
    }, {
      collection: 'userInfo'
    });
var UserDetails = mongoose.model('userInfo', UserDetail);

这是我在路由文件中的 post 方法

//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');
        }
    });
});

我的 get api 工作完美。josn 看起来像这样:

{"username":"exmpleUsername","password":"examplePassword","_id":"54091d9df8f00fb42055b6f8","__v":0}

但是当我尝试使用 POSTMAN 发布时,它不会添加用户名和密码。它只是像这样添加新的_id:

{"_id":"540e394f37706f701020cf19","__v":0}

提前致谢!

4

1 回答 1

0

请检查您的架构类是否用户名和密码是私有的

var Schema = function(){

    var self = this;

    var username = ""; // mean private

    self._id = ""; // mean public

};
于 2014-09-09T00:27:28.037 回答