Construction of mongodb+nodejs environment under linux

1. To install mongodb, see the previous article: http://lovebeyond.iteye.com/blog/1770323

2. Upgrade python version. See: http://lovebeyond.iteye.com/blog/17704763

. Install the nodejs runtime environment, see: http://lovebeyond.iteye.com/blog/1770556

4. Install the mongodb driver of nodejs:
     a. Execute: cd /usr/local/node-v0.8.7/bin
     b. Execute: ./npm install mongodb

5. Test whether the mongodb+nodejs environment is successfully built:

    Create the mongo_node.js file under /usr/local/node-v0.8.7/bin, and enter the following code in the file:
var mongodb = require('mongodb');
 var server = new mongodb.Server('localhost',27017,{auto_reconnect:true});
 var db = new mongodb.Db('mydb',server,{safe:true});
 db.open(function(err,db){
     if(!err)
     {   
         console.log('connect');
     }else{
         console.log(err);
     }   
 
 });

Run the code and execute: ./node mongo_node.js

ps: If connect is output after execution, it means success, otherwise it fails.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327051193&siteId=291194637