-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.js
More file actions
33 lines (29 loc) · 980 Bytes
/
route.js
File metadata and controls
33 lines (29 loc) · 980 Bytes
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
import { MongoClient } from 'mongodb';
const uri = "mongodb+srv://srivallabhmanyam:3kkZUrfPAg6SZ12W@buildingskills.igpamrg.mongodb.net/?retryWrites=true&w=majority";
const client = new MongoClient(uri);
let db = null;
async function getDb() {
if (db) return db;
try {
await client.connect();
db = client.db('Scrapping');
return db;
} catch (error) {
console.error("Failed to connect to MongoDB:", error);
throw new Error("Database connection failed");
}
}
export async function getData() {
try {
const database = await getDb();
return {
topnews: await database.collection("topnews").find().toArray(),
layoffs: await database.collection("layoffs").findOne(),
stockdata: await database.collection("stockdata").findOne(),
insights: await database.collection("insights").findOne(),
};
} catch (error) {
console.error("Failed to get collection:", error);
throw new Error("Collection access failed");
}
}