forked from Revathi-80/login-page
-
Notifications
You must be signed in to change notification settings - Fork 2
/
db.js
32 lines (24 loc) · 855 Bytes
/
db.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
const mongoose = require('mongoose');
const mongoURI = "mongodb://localhost:27017";
const User = require('./schema/User');
async function createNewUser() {
const checkMultipleUsers1 = await User.findOne({ email: 'test@new.com' });
if (!checkMultipleUsers1) {
const user= new User({email: 'test@new.com',username: 'test',password: 'test123'});
const result = user.save(function(err, data) {
if (err) return console.error(err);
console.log("done", data)
});
console.log(result);
}
else{
console.log("collection exist");
}
}
const connectToMongo = () => {
mongoose.connect(mongoURI, { dbName: 'webauth' }, () => {
console.log("Connected To Mongo Successfully!!");
});
createNewUser();
};
module.exports = connectToMongo;