-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.js
More file actions
21 lines (15 loc) · 750 Bytes
/
mongodb.js
File metadata and controls
21 lines (15 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//CRUD create read update delete
const { MongoClient, ObjectID} = require('mongodb')
const connectionURL = 'mongodb://127.0.0.1:27017'
const databaseName = 'task-manager' //This will show as a database in the Robo 3T
MongoClient.connect(connectionURL, { useNewUrlParser: true }, (error, client) => {
//This is a Asyncrones method
if(error){
// The return stops the code from continue its execution
return console.log('Unable to connect to database!')
}
// Client.db is the name of the db you trying to manipulate
const db = client.db(databaseName) // It gives you back a database reference; typically store in verbal called db
//The user is just a function argument
// ODM means object document mapper
})