First time it saves client to database and second time it gives 500 error

 Client.findOne({ email: }, function (err, user) {
      // Make sure user doesn't already exist
      if (user) return res.status(400).send({ msg: 'The email address you have entered is already associated with another account.' });
      // Create and save the user
     Client.create({ username:, email:, phone:, password: req.body.password }, function(err, client) {
          if (err) { return res.status(500).send({ msg: err.message }); }

          // Create a verification token for this user
          var token = new Token({ _userId: client._id, token: crypto.randomBytes(16).toString('hex') });
          // Save the verification token
 (err) {
              if (err) { return res.status(500).send({ msg: err.message }); }

What is Client? what is Token? Where are you getting these object definitions from? What kind of database are you writing to?

I have defined schema definitions in another file then I am creating instance of them.

The problem got solved it occurs due to duplicate indexes.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.