简体   繁体   English

如何在猫鼬数据库中添加用户信息?

[英]how to add user's information in mongoose database?

i have a registration form in .jade format 我有.jade格式的注册表

form(method='post', action='/users/register', enctype='multipart/form-data')
      .form-group
          label Name
          input.form-control(name='name', type='text', placeholder='Enter Name' required)
      .form-group
          label Email
          input.form-control(name='email', type='email', placeholder='Enter Email' required)
      .form-group
          label Username
          input.form-control(name='username', type='text', placeholder='Usernamee' required)
      .form-group
          label Password
          input.form-control(name='password', type='password', placeholder='Enter Password' required)
      .form-group
          label Password
          input.form-control(name='password2', type='password', placeholder='Confirm Password' required)
      .form-group
          label Profile Image
          input.form-control(name='profileimage', type='file')
      input.btn.btn-default(name='submit', type='submit', values='Register') 

and this is how i'm creating a new user and trying to add them to the database but the data is not being added into the database. 这就是我创建新用户并将其添加到数据库中的方法,但是数据并未添加到数据库中。 The problem is it's not taking values from the form fields: name, email username, password are all NULL I don't understand why as it's supposed to take all values 问题是它没有从表单字段中获取值:名称,电子邮件用户名,密码都为NULL我不知道为什么,因为它应该采用所有值

router.post('/register', function(req, res, next) {
var newUser = new User({
          name: req.body.name, 
          email: req.body.email,
          username: req.body.username,
          password: req.body.password,
          profileImage: profileImageName
      });
}

You need a body parsing middleware to parse incoming request bodies. 您需要一个主体解析中间件来解析传入的请求主体。

Express has a built-in middleware function (which is based on the body-parser module) to parse urlencoded bodies since v4.16.0 onwards. 从v4.16.0开始,Express具有内置的中间件功能 (基于body-parser模块)来解析经过urlencoded的主体。 But this built-in parser does not handle multipart bodies. 但是,此内置解析器无法处理多部分主体。

Since you're trying to handle a multipart/form-data , you may need a middleware like multer . 由于您尝试处理multipart/form-data ,因此可能需要像multer这样的中间件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果日期晚于今天,如何不将用户添加到数据库中? - How to not add the user to the database if the date is later than today's date? 如何在Firebase实时数据库中检索用户信息 - How to retrieve information of a user in firebase realtime database 如何使用 javascript 在 firebase 中添加用户的额外信息,例如显示名称? - How to add user's extra information such as display name in firebase using javascript? 如何使用 mongoose 中具有用户 ID 的帖子填充用户? - How to populate the users with the posts that have the user's id in mongoose? 如何使用 FB.login() 获取 facebook 的用户信息 - How to get facebook's user's information with FB.login() 如何在猫鼬中添加通知? - How to Add Notifications in mongoose? 从数据库中的用户获取信息 - GET information from user in database ExtJS:如何仅将用户的登录信息存储一次? - ExtJS: How to store a user's login information only once? 如何在Firebase中访问用户的Facebook公共信息? - How to access the user's facebook public information in firebase? 如何使用JavaScript SDK获取Facebook用户的朋友信息 - How to get Facebook user's friends information using JavaScript SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM