-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBsetup.js
More file actions
49 lines (45 loc) · 1.28 KB
/
DBsetup.js
File metadata and controls
49 lines (45 loc) · 1.28 KB
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
48
49
const { MongoClient, ServerApiVersion } = require("mongodb");
var { mongoUsername, mongoPassword, mongoUrl } = require("./config.json");
var monogDBuri = `mongodb+srv://${mongoUsername}:${mongoPassword}@${mongoUrl}/?retryWrites=true&w=majority`;
console.log(monogDBuri);
const client = new MongoClient(monogDBuri, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverApi: ServerApiVersion.v1,
});
async function connect() {
try {
await client.connect();
console.log("Connected correctly to server");
} catch (err) {
console.log(err.stack);
}
}
connect();
async function createUserCollection() {
try {
const db = client.db("Discbot");
const collection = db.collection("users");
await collection.insertOne({
_id: "123456789",
username: "firstTestUser",
hasAllowedAccess: false,
hasSessionKey: false,
sessionKey: null,
});
console.log("Created collection");
} catch (err) {
console.log(err.stack);
}
}
createUserCollection();
async function close() {
try {
await client.close();
console.log("Closed connection");
} catch (err) {
console.log(err.stack);
}
}
close();
console.log("Setup complete");