I am trying to connect to mongod server to test my connection with node js.
Here is the code for app.js which i am trying to run -
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localohost:27017/test',function(err,db){
if(err)
throw err;
db.mycollection().findOne({},function(err,doc){
if(err)
throw err;
console.dir(doc);
db.close();
});
console.dir('called');
});
When i ran it for first time it gave me an error that mongodb module not found - after i installed
npm install mongodb
I started my mongod server in another cmd. but when i am running node app.js it gives me error -
C:\Users\SONY\Desktop\python pakka\node_modules\mongodb\lib\mongodb\mongo_client
.js:409
throw err
^
Error: failed to connect to [localohost:27017]
at null.<anonymous> (C:\Users\SONY\Desktop\python pakka\node_modules\mongodb
\lib\mongodb\connection\server.js:546:74)
at emit (events.js:106:17)
at null.<anonymous> (C:\Users\SONY\Desktop\python pakka\node_modules\mongodb
\lib\mongodb\connection\connection_pool.js:150:15)
at emit (events.js:98:17)
at Socket.<anonymous> (C:\Users\SONY\Desktop\python pakka\node_modules\mongo
db\lib\mongodb\connection\connection.js:533:10)
at Socket.emit (events.js:95:17)
at net.js:833:16
at process._tickCallback (node.js:419:13)
I am a beginner in this. Can anybody help me out.
I think what tymeJV is saying is that you have a misspelling in your mongodb url. It should be "mongodb://localhost:27017/test", not localohost.