Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when i try to my second email its showing this error #23

Open
being-nitin opened this issue Jul 28, 2022 · 1 comment
Open

when i try to my second email its showing this error #23

being-nitin opened this issue Jul 28, 2022 · 1 comment

Comments

@being-nitin
Copy link

E11000 duplicate key error collection: userDB.users index: username_1 dup key: { username: null }

@adxthya
Copy link

adxthya commented Jan 4, 2024

This can be fixed by adding a username element to your schema.

const userSchema = new mongoose.Schema({
  username: String,
  name: String,
  googleId: String,
  message: String,
  picture: String,
  messages: Array,
});

Then in findOrCreate add

function (accessToken, refreshToken, profile, cb) {
      // console.log(profile);
      User.findOrCreate(
        {
          googleId: profile.id,
          name: profile.name.givenName,
          picture: profile._json.picture,
          username: profile.displayName,
        },
        function (err, user) {
          return cb(err, user);
        }
      );
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants