Rumah  >  Soal Jawab  >  teks badan

node.js - nodejs连接mongodb失败的问题

前些天用python做了一个能发文章的博客,最近学习了nodejs,准备用nodejs也来做一遍,可是当我连接MongoDB的时候遇上了*烦。
不管我用mongo 或者mongoose都会提示

{ [MongoError: failed to connect to server [localhost:27017] on first connect]
  name: 'MongoError',
  message: 'failed to connect to server [localhost:27017] on first connect' }

先说明一下,O(∩_∩)O~

1.我的MongoDB开着,版本2.0.0 。而且可用MongoDB自带的mongo连接。
2.我的系统是Windows Xp
3.我用python可以连接MongoDB
4.mongoose版本: ^4.5.7"

贴一下代码

var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/test',function(err){
    if(err){
        console.log('连接数据库错误!');
        console.log('错误信息:\n\t');
        console.log(err);
    }else{
        console.log('Success!!!');
    }
})

尝试了网上说的删除mongod.lock,还有尝试mongodb://127.0.0.1:27017/test连接都不行,是不是xp系统的问题?还是连接权限的问题?请大神指教!!!

天蓬老师天蓬老师2713 hari yang lalu407

membalas semua(1)saya akan balas

  • 阿神

    阿神2017-04-17 15:02:53

    https://docs.mongodb.com/manu...

    Starting in version 2.2, MongoDB does not support Windows XP. Please use a more recent version of Windows to use more recent releases of MongoDB.

    虽然很好奇你是从哪里找到2.0的版本的,大概已经是4、5年前的版本了。不过如果实在要这么用的话,你需要找到对应2.0的驱动。

    balas
    0
  • Batalbalas