1

i installed mongodb via npm using

npm install mongodb 

Which installed 1.4.32 version of mongodb driver. The code given at the bottom worked fine, but when i upgraded my driver ( and deleted the older folder of 1.4.32 from node modules, updated package.json) i'm getting the following error:

unknown system error : 10042. 

I looked up on search engines and its a windows winsock error, don't know why i get this with the latest version but not with the earlier version..

I guess its something to do with replicaSet option in url, i dont know how to set it, i mean i tried

mongodb://localhost/test?replicaSet=rs0-1

but is that all we need to configure a replica set, how can we use null for replica set..

here's the connection code i used in nodeJS that works fine with 1.4.* of mongodb native driver but doesn't work with 2.0.18 of mongodb native driver.

var express = require('../Express2/node_modules/express');
var app = express(); // instantiate the express object thru its constructor
var path = require('path');
var assert = require('assert');
var mongodb = require('mongodb'); // 2.0.18

// use /public directory for serving web pages first
app.use(express.static(path.join(__dirname , '/public'))); // add current directory

// when a request for /insert is received
app.get("/insert",function(req,resp){
  // Create a mongo client
  var mongoClient = mongodb.MongoClient;

  // configure url to connect to
  var url = 'mongodb://localhost:27017/test';
  //mongodb://user:pass@ipaddr:port/dbname

  // try to connect and get db handle
  mongoClient.connect(url,function(err,db){
    if(err){
      console.log(err.toString()); // Error thrown here..
    }
    else{
      console.log('successfully connected to mongod server');
      var collectionStudent = db.collection('student');
      // accepts obj and callback.
      collectionStudent.insert(
        {name:'Andrew',courses:[{subject:'RDBMS',fee:15000}]},
        function(err,result){
          resp.send('Result of insertion:' + JSON.stringify(result));
          resp.end();
          db.close();
        }
      );
    }
  });

});

// for pages not found in public directory, do this:
app.get("*",function(req,resp){
  resp.sendFile(path.join(__dirname , "/public/404.html"));
});

// any other special routes like /result etc appear below this line
//..
//..
app.listen(3000);
Bharat
  • 152
  • 1
  • 9
  • I think the error didn't get pasted in. Could you edit in the error message? – wdberkeley Mar 02 '15 at 18:25
  • If you are still facing the issue - It is due to version of mongodb with Win XP. Pls refer - http://stackoverflow.com/questions/31228809/mongoerror-connect-unknown – khushboo29 Jan 07 '16 at 12:15

1 Answers1

1

Try using

 var url = 'mongodb://127.0.0.1:27017/test';

or

 var url = 'mongodb://0.0.0.0:27017/test';

Also, check the implication of 0.0.0.0

Instead of

localhost

  var url = 'mongodb://localhost:27017/test';
roxylius
  • 31
  • 3