-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4764 from Giveth/remove-mongoDB-inserOne
changed mogoDb connection and insertOne method
- Loading branch information
Showing
4 changed files
with
113 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as mongoDB from 'mongodb'; | ||
|
||
let mongoClient: mongoDB.MongoClient; | ||
|
||
export async function connectToMongo() { | ||
const url = process.env.MONGO_DONATION_CONNECTION_URI; | ||
if (!url) { | ||
throw new Error('MONGODB_CONNECTION_URL is not set'); | ||
} | ||
if (!mongoClient) { | ||
mongoClient = new mongoDB.MongoClient(url); | ||
await mongoClient.connect(); | ||
} | ||
return mongoClient; | ||
} | ||
|
||
export async function getMongoDB(): Promise<mongoDB.Db> { | ||
const client = await connectToMongo(); | ||
return client.db(process.env.MONGO_DONATION_DATABASE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters