I'm trying to save to a user collection in mongodb using mongoose and I'm getting the following
Error: ReferenceError: Cannot access 'user' before initialization.
const user = mongoose.model("users");
try {
const user = await new user({
googleId: profile.id,
name: profile.displayName,
email: profile.emails[0].values
}).save();
done(null, user);
} catch (err) {
console.log("error " + err);
}
}
Here is my user.js file:
const mongoose = require("mongoose");
const { Schema } = mongoose;
const userSchema = new Schema({
googleId: String,
name: String,
email: String
});
mongoose.model("users", userSchema);
usersobject formuser.jsmodel file. Can you please share the whole codebase of the first code snippet and also the folder structure?