有没有办法在 Meteor 启动时从 MySQL 数据库导入数据?我基本上只需要来自 MySQL 的初始数据即可将其导出到 Mongo 集合以供使用。

最佳答案

您最好的选择可能是只使用 mysql 节点包(记住使用 Meteor.npmRequire(..) 而不是 require(..) )。这个好像不错:

https://github.com/felixge/node-mysql

这样的事情应该工作:

if (Meteor.isServer) {
    var mysql = Meteor.npmRequire('mysql');
    Meteor.startup(function() {
        var connection = mysql.createConnection({
            host     : 'localhost',
            user     : 'me',
            password : 'secret'
        });

        connection.connect();

        connection.query('SELECT * FROM table', function(err, rows, fields) {
            if (err) throw err;
            // create documents from rows[i] and add to your collection
        });

        connection.end();

    });
}

关于mysql - 如何从 meteor 访问mysql db,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20615713/

10-11 22:43
查看更多