Skip to content
Snippets Groups Projects
db.js 1.78 KiB
Newer Older
import dotenv from 'dotenv';
import mongoose from 'mongoose';
Gwangbin's avatar
Gwangbin committed

dotenv.config();

// const GoogleProviderSchema = new mongoose.Schema({
//   id: {
//     type: String,
//     required: true,
//     //unique: true,
//   },
//   profileUrl: {
//     type: String,
//   },
// });
Gwangbin's avatar
Gwangbin committed

// const UserSchema = new mongoose.Schema({
//   nickname: {
//     type: String,
//   },
//   email: {
//     type: String,
//     //unique: true,
//   },
//   google: {
//     type: GoogleProviderSchema,
//   }
// });
Gwangbin's avatar
Gwangbin committed

Hyun Woo Jeong's avatar
Hyun Woo Jeong committed

// const UserModel = mongoose.model("User", UserSchema);
Gwangbin's avatar
Gwangbin committed

// const CommentSchema = new mongoose.Schema({
//   content: {
//     type: String,
//     required: true,
//   },
//   author: {
//     type: UserSchema,
//     required: true,
//   },
//   createdAt: {
//     type: Date,
//     default: Date.now,
//   },
// });
// CommentSchema.index( { commentId: 1 } , { sparse: true } )
Gwangbin's avatar
Gwangbin committed

// const ArticleSchema = new mongoose.Schema({
//   title: {
//     type: String,
//     required: true,
//   },
//   content: {
//     type: String,
//     required: true,
//   },
//   imageUrls: {
//     type: [String],
//   },
//   author: {
//     type: UserSchema,
//     required: true,
//   },
//   comments: {
//     type: [CommentSchema],
// 	unique: false,
//   },
//   likes: {
//     type: [UserSchema],
//   },
//   createdAt: {
//     type: Date,
//     default: Date.now,
//   },
// });
Gwangbin's avatar
Gwangbin committed

// ArticleSchema.index({articleId:1}, { sparse: true })
// const ArticleModel = mongoose.model("Article", ArticleSchema);
Gwangbin's avatar
Gwangbin committed

const connectDB = async () => {
  const url = process.env.MONGODB_URI;
  try {
    await mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true });
    console.log('Database connected');
Gwangbin's avatar
Gwangbin committed
  } catch (error) {
    console.error('Database connection failed',error);
Gwangbin's avatar
Gwangbin committed
  }
Gwangbin's avatar
Gwangbin committed

export default connectDB;