MongoError: E11000 duplicate key error index
<p>My database schema is</p>

<pre><code>var Account = new Schema({
    email : String,
    name : String ,
   family : String ,
   password : String
   });
</code></pre>

<p>I want to use email and password for authentication with passport. my code is:  </p>

<pre><code>var LocalStrategy = require('passport-local').Strategy;
passport.use('register', new LocalStrategy({
    usernameField: 'email',
    passwordField: 'password',
    passReqToCallback : true
},
function(req, email, password, done) {
        Account.findOne({ 'email' :  email }, function(err, user) {
            if (err)
            {
                return done(err);
            }
                else
                {
                var newaccount = new Account();

                newaccount.password = bcrypt.hashSync(req.body.password);
                newaccount.email = req.body.email;
                newaccount.name = req.body.name;
                newaccount.family = req.body.family;

                // save the user
                newaccount.save(function(err) {
                    if (err)
                    {
                        console.log('Error in Saving user: '+err);
                        throw err;
                    }
               }
        });
</code></pre>

<p>Although I don't have any username field in </p>

<pre><code>MongoError: E11000 duplicate key error index: Account.accounts.$username_1       dup key: { : null }
</code></pre>

<p>The first time I can insert in database and I don't have any error but for second time I have this error that I think it assumes username as key and in first time it sets username as null so for second time that it want to try to set username as null throw error because of duplicate key. I search the internet a lot . I drop the database and I use  <code>db.Account.dropIndexes()</code> but the problem was not solved. </p>