Harrymissu
Harrymissu

Reputation: 470

no data in mongodb after insert

Everything works fine when I insert data to database. But I can't find the data inserted in robo 3T interface.....

code:

const MongoClient = require('mongodb').MongoClient;

MongoClient.connect('mongodb://localhost:27017/TodoApp',{ useNewUrlParser: true },(err,client) =>{
    if(err) {
        return console.log('Unable to connect to MongoDB server');
    }
    console.log('Connected MongoDB server');
    const db = client.db('TodoApp');

    db.collection('Todos').insertOne({
        text: 'Something to do',
        completed: false
    },(err,result) => {
        if(err){
            return console.log('Unable to insert todo',err);
        }

        console.log(JSON.stringify(result.ops,undefined,2));
    });

     client.close();
});

it is the terminal result after I run js code

this is the Robo 3T interface where I can not find the data I inserted

Upvotes: 0

Views: 333

Answers (1)

nosleepfilipe
nosleepfilipe

Reputation: 76

In you nodejs URL you are connecting to the ’TodoApp’ database and in your robomongo, you are connected to the ’test’ database

Upvotes: 2

Related Questions