Skip to content

Commit e9564f4

Browse files
committed
react driven db insert
1 parent e23056f commit e9564f4

File tree

623 files changed

+159829
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

623 files changed

+159829
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const mongodb = require('mongodb');
2+
const MongoClient = mongodb.MongoClient;
3+
4+
const mongo_url = "mongodb://127.0.0.1:27017/";
5+
6+
console.log(MongoClient);
7+
8+
function getConnectedDB(db_name) {
9+
return new Promise((resolve, reject) => {
10+
MongoClient.connect(
11+
mongo_url,
12+
{
13+
useNewUrlParser: true,
14+
useUnifiedTopology: true
15+
}
16+
)
17+
.then((connection) => {
18+
resolve(connection.db(db_name));
19+
})
20+
.catch((error) => {
21+
reject(error);
22+
});
23+
});
24+
}
25+
26+
exports.getConnectedDB = getConnectedDB;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const DBConnector = require('../db/connect');
2+
3+
4+
function getCollection() {
5+
return new Promise((resolve, reject) => {
6+
DBConnector
7+
.getConnectedDB('practice')
8+
.then((db) => {
9+
resolve(db.collection('users'));
10+
})
11+
.catch((error) => {
12+
reject(error);
13+
})
14+
})
15+
}
16+
17+
exports.getCollection = getCollection;

Practice/Express-React/backend/node_modules/.package-lock.json

Lines changed: 218 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Practice/Express-React/backend/node_modules/@types/node/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)