-
Notifications
You must be signed in to change notification settings - Fork 7
/
mongo.js
50 lines (42 loc) · 1.38 KB
/
mongo.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
39
40
41
42
43
44
45
46
47
48
49
50
import mongoose from "mongoose";
mongoose.set('strictQuery', false);
/** set model by schema */
import apiKeys from './src/schemas/apikeys.js';
import savedNotes from './src/schemas/notes.js';
import barkuni from './src/schemas/barkuni.js';
import kupaRashit from "./src/schemas/kupaRashit.js";
import mediaNote from './src/schemas/mediaNote.js';
export default class Mongo {
isConnected = false;
constructor() {
this.mongoose = mongoose;
this.apiKeys = apiKeys;
this.savedNotes = savedNotes;
this.barkuni = barkuni;
this.kupaRashit = kupaRashit;
this.mediaNote = mediaNote;
this.connectionString = process.env.MONGOOSE + '/API_KEYS'//?retryWrites=true&w=majority'
this.connection = mongoose.connection;
mongoose.connect(this.connectionString, {
useNewUrlParser: true,
ssl: true,
sslValidate: false
})
this.connection.once("open", () => {
console.log("MongoDB database connection established successfully");
this.isConnected = true;
});
this.connection.once("close", () => {
console.log("MongoDB database connection has been closed");
this.isConnected = false;
});
}
/**
* can take one argument of key
* @param {{name: String, apikey: String, phone: String}} key
*/
async findApiKey(key) {
if (this.isConnected)
return (await this.apiKeys.findOne(key))?.toJSON()
}
}