-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbUtil.ts
More file actions
31 lines (27 loc) · 1.32 KB
/
dbUtil.ts
File metadata and controls
31 lines (27 loc) · 1.32 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
import { promisifyAll } from 'bluebird';
const MongoClient = promisifyAll(require('mongodb')).MongoClient;
// use when starting application locally
let mongoUrlLocal = "mongodb://admin:admin@localhost:27017";
// use when starting application as docker container
let mongoUrlDocker = "mongodb://admin:admin@mongodb";
// pass these options to mongo client connect request to avoid DeprecationWarning for current Server Discovery and Monitoring engine
let mongoClientOptions = { useNewUrlParser: true, useUnifiedTopology: true };
const databaseObj = "EmailInfo";
const collectionObj = "EmailInfo";
export async function retrieveUserIdObjects() {
const db = await MongoClient.connectAsync(mongoUrlDocker, mongoClientOptions);
const dbo = await db.db(databaseObj);
const collection = await dbo.collection(collectionObj);
const colle = await collection.findAsync({});
const result = await colle.toArray();
await db.close();
return result;
}
export async function insertObject(email: string, district_: Number) {
const db = await MongoClient.connectAsync(mongoUrlDocker, mongoClientOptions);
const dbo = await db.db(databaseObj);
const collection = await dbo.collection(collectionObj);
const myobj = { emailId: email, district : district_};
await collection.insertOneAsync(myobj);
await db.close();
}