Jack C
Jack C

Reputation: 1084

Mongo create user error using passport authentication

I am using MEAN.IO stack (default template with Mongoose) and Passport.js authentication to create new users. Whenever user.save(...) is called in the below code:

// Use Facebook strategy
passport.use(new FacebookStrategy({
    clientID: config.strategies.facebook.clientID,
    clientSecret: config.strategies.facebook.clientSecret,
    callbackURL: config.strategies.facebook.callbackURL
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOne({
      'facebook.id': profile.id
    }, function(err, user) {
      if (user) {
        return done(err, user);
      }
      user = new User({
        name: profile.displayName,
        email: profile.emails[0].value,
        provider: 'facebook',
        facebook: profile._json,
        roles: ['authenticated']
      });
      user.save(function(err) {
        if (err) {
          console.log(err);
          return done(null, false, {message: 'facebook login failed, email already used by other login strategy'});
        } else {
          return done(err, user);
        }
      });
    });
  }
));

The console logs the following error:

MongoError: attempt to use unsupported textIndexVersion 2, only textIndexVersion 1 supported

I've looked online and through the MEAN.IO stack code and can't find anything about how to change the textIndexVersion.

Any ideas how to change the version or fix this error in general?

Upvotes: 0

Views: 164

Answers (1)

br0tat0
br0tat0

Reputation: 539

According to the bug reports for Mongo:

mongod v2.4.9 will correctly forbid changes to collections that have a text index which is incompatible with 2.4. Attempts to insert, update, or remove documents in these collections will return the error message "attempt to use unsupported textIndexVersion 2, only textIndexVersion 1 supported".

https://jira.mongodb.org/browse/SERVER-11494

I would suggest updating your Mongo version to be compatible with v2.4.9

Upvotes: 1

Related Questions