Issues (82)

app/experiments/mongo-update.js (6 issues)

1
'use strict';
2
const {MongoClient} = require('mongodb');
3
4
MongoClient.connect('mongodb://localhost:27017/JokesApp', (err, db) => {
5
    if (err) {
6
        return console.log('error connecting to mongodb server');
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
7
    }
8
9
    console.log('connected to mongodb server');
10
11
    db.collection('Jokes').findOneAndUpdate({
12
        joke : 'Sample joke'
13
    },
14
    {
15
        $set : {
16
            joke : 'This was updated joke',
17
            likes : 1
18
        }
19
    }, {
20
        returnOriginal : true
21
    }).then((updatedDoc) => {
22
        console.log(updatedDoc);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
23
    }, (err) => {
24
        console.log('Error updating. E: ', err);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
25
    });
26
27
    // display all the jokes after updating 
28
    db.collection('Jokes').find().toArray().then((docs) => {
29
        console.log(docs);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
30
    }, (err) => {
31
        console.log('error displaying all jokes. E: ', err);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
32
    });
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...
33
    //db.close();
34
});