当我将数据插入数据库时,一切正常。但是我找不到在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();
});
答案 0 :(得分:2)
在您的nodejs URL中,您正在连接至“ TodoApp”数据库,在robomongo中,您已连接至“测试”数据库