-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbConection.js
27 lines (22 loc) · 911 Bytes
/
dbConection.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
/* Conexion con MongoDB Atlas usando mongoose */
const db = require("mongoose")
function connect(url){
db.Promise = global.Promise // Establece a mongoose el uso de la libreria de promesas que es global
db.connect(url, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log("Conexion exitosa"))
.catch(error => console.log(error))
}
module.exports = connect
/* Conexion con MongoDB usando MongoClient*/
// const MongoClient = require('mongodb').MongoClient;
// const uri = "mongodb+srv://root:r00t@clusternodejs.jcrm1.mongodb.net/telegrom?retryWrites=true&w=majority"
// const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true })
// client.connect(err => {
// if (err){
// console.log(err)
// throw err
// }
// const db = client.db("telegrom")
// console.log(db)
// // client.close()
// })