I can\'t find documentation on this function and therefor I can\'t make it work right. When is that function being called, what is it doing and what is it taking as first pa
If you would like to use findOrCreate, try the npm package mongoose-findorcreate, or supergoose
e.g. mongoose-findorcreate
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost');
var findOrCreate = require('mongoose-findorcreate')
var Schema = mongoose.Schema;
var UserSchema = new Schema({ facebookId: Number});
UserSchema.plugin(findOrCreate);
var User = mongoose.model('User', UserSchema);
passport.use(new FacebookStrategy({
clientID: 'clientID',
clientSecret: 'clientSecret',
callbackURL: "/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, cb) {
User.findOrCreate({ facebookId: profile.id }, function (err, user) {
console.log('A new uxer from "%s" was inserted', user.facebookId);
return cb(err, user);
});
}
));