1 | // import MongoClient from the mongodb package |
||
2 | const {MongoClient} = require('mongodb'); |
||
3 | |||
4 | // connect to mongodb server |
||
5 | MongoClient.connect('mongodb://localhost:27017/JokesApp', (err, db) => { |
||
6 | if (err) { |
||
7 | return console.log('Failed to connect to mongoDB server : ' + err); |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
8 | } |
||
9 | |||
10 | console.log('Connected to MongoDB Server'); |
||
11 | |||
12 | //get the count of jokes stored |
||
13 | db.collection('Jokes').count().then((count) => { |
||
14 | console.log(`Jokes count = ${count}\n`); |
||
0 ignored issues
–
show
|
|||
15 | }, (err) => { |
||
16 | if (err) { |
||
0 ignored issues
–
show
There is no return statement if
err is false . Are you sure this is correct? If so, consider adding return; explicitly.
This check looks for functions where a Consider this little piece of code function isBig(a) {
if (a > 5000) {
return "yes";
}
}
console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined
The function This behaviour may not be what you had intended. In any case, you can add a
![]() |
|||
17 | return console.log('error getting count', err); |
||
0 ignored issues
–
show
|
|||
18 | } |
||
19 | }); |
||
20 | |||
21 | // fetch all the jokes/documets with 10 likes |
||
22 | db.collection('Jokes').find({likes : 10}).toArray().then((docs) => { |
||
23 | console.log(JSON.stringify(docs, undefined, 2)); |
||
0 ignored issues
–
show
|
|||
24 | }, (err)=> { |
||
25 | if (err) { |
||
0 ignored issues
–
show
There is no return statement if
err is false . Are you sure this is correct? If so, consider adding return; explicitly.
This check looks for functions where a Consider this little piece of code function isBig(a) {
if (a > 5000) {
return "yes";
}
}
console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined
The function This behaviour may not be what you had intended. In any case, you can add a
![]() |
|||
26 | return console.log('Fetch error : ', err); |
||
0 ignored issues
–
show
|
|||
27 | } |
||
28 | }); |
||
29 | |||
30 | //fetch all the users from the db |
||
31 | db.collection('Users').find().toArray().then((docs) => { |
||
32 | // print all the users |
||
33 | console.log(JSON.stringify(docs, undefined, 2)); |
||
0 ignored issues
–
show
|
|||
34 | }, (err) => { |
||
35 | if(err) { |
||
0 ignored issues
–
show
There is no return statement if
err is false . Are you sure this is correct? If so, consider adding return; explicitly.
This check looks for functions where a Consider this little piece of code function isBig(a) {
if (a > 5000) {
return "yes";
}
}
console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined
The function This behaviour may not be what you had intended. In any case, you can add a
![]() |
|||
36 | return console.log('Error Fetching users : ', err); |
||
0 ignored issues
–
show
|
|||
37 | } |
||
38 | }); |
||
0 ignored issues
–
show
|
|||
39 | |||
40 | //db.close(); |
||
41 | }); |