-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongodb-connect.js
42 lines (35 loc) · 980 Bytes
/
mongodb-connect.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
33
34
35
36
37
38
39
40
41
42
// const MongoClient = require('mongodb').MongoClient;
const { MongoClient, ObjectID} = require('mongodb');
const config = {
useNewUrlParser: true,
};
MongoClient.connect('mongodb://localhost:27017/TodoApp', config, (err, client) => {
if (err) {
return console.log('Unable to connect to MongoBD server')
}
console.log('Connected');
const db = client.db('TodoApp')
// db.collection('Todos').insertOne({
// text: "Something to do",
// copmleted: false
// }, (error, result) => {
// if (error) {
// return console.log('Unable to insert todo', error)
// }
//
// console.log(JSON.stringify(result.ops, undefined, 2))
//
// });
// db.collection('Users').insertOne({
// name: "ROMAN",
// age: 25,
// location: "Lviv"
// }, (error, result) => {
// if (error) {
// return console.log('Unable to insert todo', error)
// }
//
// console.log(JSON.stringify(result.ops))
// })
client.close();
});