You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a Model via Mongoose aka Collection in Mongo DB
const mongoose = require('mongoose');
const {Schema} = mongoose;
//Schema means structure for records going in Users Model
const userSchema = new Schema({
googleId: String
})
mongoose.model('users', userSchema);
Use Mongoose to Create a record into model
require('../models/User');
const User = mongoose.model('users');
new User({ googleId: profile.id }).save()
check if user exists not then register yes then skip
const userExists = await User.findOne({ googleId: profile.id});
if(userExists) {
//user already exists
done(null, userExists);
} else {
// create a new user
const user = await new User({ googleId: profile.id }).save();
done(null, user);
}