Is there a way to import data from MySQL database on Meteor startup? I basically need just an initial data from MySQL to export it to Mongo collections for usage.
Asked
Active
Viewed 3,121 times
1 Answers
4
Your best bet might be to just use a mysql node package (remember to use Meteor.npmRequire(..)
instead of require(..)
). This one seems good:
https://github.com/felixge/node-mysql
Something like this should work:
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();
});
}

Christian Fritz
- 20,641
- 3
- 42
- 71