Issues (82)

app/experiments/mongo-connect.js (9 issues)

1
'use strict';
2
3
const {MongoClient} = require('mongodb');
4
5
MongoClient.connect('mongodb://localhost:27017/JokesApp', (err, db) => {
6
    if (err) 
7
        return console.log('unable to connect MongoDB' + err);      
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8
    console.log('Connected to MongoDB Server');
9
10
    // creating a new collection, a table like structure
11
    db.collection('Jokes').insertOne({
12
        joke : 'Sample joke 2',
13
        likes : 0,
14
    }, (err, result) => {
15
        if (err) 
16
            return console.log('unable to insert data' + err);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
17
        
18
        console.log(JSON.stringify(result.ops, undefined, 2));
0 ignored issues
show
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
19
    });
20
21
    // one more users collection
22
    db.collection('Users').insertOne({
23
        name : 'Ashok Dey',
24
        age : 22,
25
        location : 'Delhi'
26
    }, (err, result) => {
27
        if (err)  
28
            return console.log('Failed to insert data into the user collection');
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
29
        
30
        console.log(JSON.stringify(result.ops, undefined, 2));
0 ignored issues
show
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
31
    });
32
33
    // close the database
34
    db.close();
0 ignored issues
show
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
35
});