将Mongodb与nodejs

时间:2016-10-11 13:40:04

标签: node.js mongodb

C:\Users\abc\Desktop\node>node connectiom.js
  

module.js:327

throw err;
^
     

错误:找不到模块' C:\ Users \ abc \ Desktop \ node \ connectiom.js'

at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3

代码是:

var mongodb = require('mongodb');

var MongoClient = mongodb.MongoClient;

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

MongoClient.connect(url, function (err, db) {

    if (err) {
        console.log('Unable to connect to the mongoDB server. Error:', err);
    } else {

        console.log('Connection established to', url);


        db.close();
    }
});

0 个答案:

没有答案