MongoDB使用中的问题

来源:互联网 发布:c语言struct 编辑:程序博客网 时间:2024/05/19 13:08

1.

Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused

我是在mac osx下运行,每次开机需要运行mongod命令,不然就会报出这个错误

2.

/Users/apple/Desktop/save/node_modules/mongodb/lib/topology_base.js:98  var maxNumberOfDocsInBatch = ismaster.maxWriteBatchSize || 1000;                                       ^TypeError: Cannot read property 'maxWriteBatchSize' of null

这是在往数据库里写数据时出现的

错误代码:

var open = function(err,db){    db.createCollection('art1',{safe:true},function(err,collection){    if(err){         console.log(err);    }    else{        console.log('find!');        var temp1 = {title:'hahah'};        var temp2 = {title:'hahaa'};        collection.insert([temp1,temp2],{safe:true},function(err,result){        console.log(result);        });        console.log('finish');    }    });};open(db);

换了一种写法后:

db.open(function(err,db){    db.createCollection('art1',{safe:true},function(err,collection){    if(err){         console.log(err);    }    else{        console.log('find!');        var temp1 = {title:'hahah'};        var temp2 = {title:'hahaa'};        collection.insert([temp1,temp2],{safe:true},function(err,result){        console.log(result);        });        console.log('finish');    }    });});

也不知道是哪里出了问题,再看看

0 0