1 | const {MongoClient} = require('mongodb'); |
||
2 | |||
3 | MongoClient.connect('mongodb://localhost:27017/JokesApp', (err, db) => { |
||
4 | if (err){ |
||
5 | return console.log('failed to connect to mongodb server. ', err); |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
6 | } |
||
7 | |||
8 | console.log('Connected to MongoDB Server'); |
||
9 | |||
10 | //deleteMany - delete all the occcurences |
||
11 | db.collection('Jokes').deleteMany({joke : 'Sample joke 2'}).then((result) => { |
||
12 | console.log(result.result); |
||
0 ignored issues
–
show
|
|||
13 | }, (err) => { |
||
14 | cosole.log('Error deleting many. E : ', err) |
||
0 ignored issues
–
show
The variable
cosole seems to be never declared. If this is a global, consider adding a /** global: cosole */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
15 | }); |
||
16 | |||
17 | //deleteOne - deletes only first occurence of all the occurences |
||
18 | db.collection('Jokes').deleteOne({joke : 'Test 1'}).then((result) => { |
||
19 | console.log(result.result); |
||
0 ignored issues
–
show
|
|||
20 | }); |
||
21 | |||
22 | db.collection('Jokes').findOneAndDelete({joke : 'Test 2'}).then((doc) => { |
||
23 | console.log(doc); |
||
0 ignored issues
–
show
|
|||
24 | }, (err) => { |
||
25 | console.log('Error find one and delete. E: ', err); |
||
0 ignored issues
–
show
|
|||
26 | }); |
||
0 ignored issues
–
show
|
|||
27 | |||
28 | //close the DB |
||
29 | // db.close(); |
||
30 | }); |