-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
25 lines (18 loc) · 918 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
const mongoose = require('mongoose');
const mongooseURI = 'mongodb+srv://dakfood:%[email protected]/dakfoodmern?retryWrites=true&w=majority';
const mongoDB = async () => {
try {
await mongoose.connect(mongooseURI, { useNewUrlParser: true, useUnifiedTopology: true });
console.log('Connected to MongoDB');
const fetched_data = await mongoose.connection.db.collection("food_items").find({}).toArray();
const foodCategory = await mongoose.connection.db.collection("foodCategory").find({}).toArray();
global.food_items = fetched_data;
global.foodCategory = foodCategory;
// console.log("Fetched data:", fetched_data);
// console.log("Fetched categories:", foodCategory);
} catch (err) {
console.error('Error connecting to MongoDB:', err);
}
};
module.exports = mongoDB;
//Hello daksh