var mysql = require('mysql');

var fs = require('fs');

var heros =null;


var client = mysql.createConnection({

    host: '112.124.54.74',  

    port: 3306,  

    user: 'yin',  

    password: '691331',  

    database: 'hu'  

});


client.connect(function(error, results) {

  if(error) {

    console.log('Connection Error: ' + error.message);

    return;

  }

  console.log('成功连接上 MySQL');

});


client.query('SELECT * from hero', function(err, rows, fields) {

    if (err) throw err;

    heros=rows;

    //console.log(heros[0]);

    fs.appendFile('log.txt',heros,'utf8',function(err){  

    if(err)  

    {  

        console.log(err);  

    }  

});  

});

client.end();


var mongodb = require('mongodb');


var server = new mongodb.Server("127.0.0.1",27017,{});//本地27017端口

var db = new mongodb.Db('mongotest', server, {safe:true});


db.open(function(err,db){//数据库:mongotest

    if(!err) 

    {

    db.collection('hero',function(err,collection){

    collection.insert(heros[0],{safe:true},function(err,result){

    console.log(result);

    });

    });

    }else{

    console.log(err);

    }

});