插入后mongodb中没有数据

时间:2018-10-15 22:59:48

标签: node.js mongodb

当我将数据插入数据库时​​,一切正常。但是我找不到在robo 3T界面中插入的数据.....

代码:

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

1 个答案:

答案 0 :(得分:2)

在您的nodejs URL中,您正在连接至“ TodoApp”数据库​​,在robomongo中,您已连接至“测试”数据库