-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solved issue: export func returned run func(),not promise
- Loading branch information
Showing
2 changed files
with
29 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
const { MongoClient } = require("mongodb"); | ||
|
||
module.exports = function (name, email, password) { | ||
module.exports = async function (name, email, password) { | ||
const uri = process.env.DB_CREDENTIALS; | ||
|
||
const client = new MongoClient(uri); | ||
let successOrFail = false; | ||
try { | ||
await client.connect(); | ||
|
||
async function run() { | ||
try { | ||
await client.connect(); | ||
const database = client.db("4learn"); | ||
const collection = database.collection("userReg"); | ||
|
||
const database = client.db("4learn"); | ||
const collection = database.collection("userReg"); | ||
// create js obj received by /register | ||
|
||
// create js obj received by /register | ||
const doc = { name: name, email: email, password: password }; | ||
const result = await collection.insertOne(doc); | ||
|
||
const doc = { name: name, email: email, password: password }; | ||
const result = await collection.insertOne(doc); | ||
|
||
console.log(`${result.insertedCount} documents were inserted into db`); | ||
} finally { | ||
await client.close(); | ||
console.log(`${result.insertedCount} documents were inserted into db`); | ||
console.log(result.insertedCount > 0); | ||
if (result.insertedCount > 0) { | ||
successOrFail = true; | ||
return true; | ||
} | ||
} finally { | ||
await client.close(); | ||
} | ||
run().catch(console.dir); | ||
}; |