-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.ts
50 lines (39 loc) · 1.06 KB
/
run.ts
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
39
40
41
42
43
44
45
46
47
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
import fs from 'fs'
import { MongoClient } from 'mongodb'
import dotenv from 'dotenv'
import path from 'path'
const envPath = path.resolve(__dirname, '.env.local');
if (fs.existsSync(envPath)) {
dotenv.config({ path: envPath });
};
(async () => {
const client = new MongoClient(process.env.MONGOURL);
try {
await client.connect();
console.log('Connected to the MongoDB server');
const db = client.db(process.env.MONGODB_DB);
let t = await db.collection("test")
let result = await t.insertMany([{
fname:"ali",
lname:"akbari",
age:22,
blance:1500
},
{
fname:"hasan",
lname:"akbari",
age:22,
blance:1500
},
{
fname:"kamran",
lname:"akbari",
age:22,
blance:1500
}])
console.log(result)
} catch {
console.log("Failed to connect to Mongo Server.")
}
})()