-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathdb.js
38 lines (32 loc) · 1004 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Import mongoose to interact with MongoDB
const mongoose = require("mongoose");
/*
const User = new mongoose.Schema({
email: String,
password: String,
name: String,
});
*/
// Use Schema and ObjectId from mongoose for creating models
const Schema = mongoose.Schema;
const ObjectId = mongoose.ObjectId;
// Define the User schema with fields for email, password, and name
const User = new Schema({
email: { type: String, unique: true }, // Make email unique to avoid duplicate entries
password: String,
name: String,
});
// Define the Todo schema with fields for title, done, and userId
const Todo = new Schema({
title: String,
done: Boolean,
userId: ObjectId,
});
// Create Mongoose models for users and todos collections using the User and Todo schemas
const UserModel = mongoose.model("users", User);
const TodoModel = mongoose.model("todos", Todo);
// Export the User and Todo models for use in other files
module.exports = {
UserModel,
TodoModel,
};