I have a mysql db with all the tables using utf8_general_ci collation. I'm using it with my PHP website and there are completely no issues with encoding.
Now I wanted to use the data from mysql tables with my node.js program. I have used node.js mysql package. This is the code I'm using to retrieve the data from mysql db:
const db = require('mysql');
const mongoose = require('mongoose');
const Event = require('./event')
mongoose.connect("mongodb+srv://xx@clustexxxx.mongodb.net/xx?retryWrites=true&w=majority" , { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log('Connected to db');
})
.catch(() => {
console.log('Connection failed!');
});
const connection = db.createConnection({
host : 'xx',
user : 'xx',
password : 'xx',
database : 'xx',
charset: 'UTF8_GENERAL_CI'
});
connection.connect();
var options = {
sql: `SELECT XXXXX`,
nestTables: false
};
connection.query(options, function (error, results, fields) {
if (error) throw error;
results.forEach(element => {
console.log(element.title);
//here I'm saving data to mongoDB
})
});
connection.end();
Once I retrieve the data with node.js, all the special characters from German, French, polish etc are broken eg: Gl�ckstadt, Mu�bach
Any advise what should I do additionally ?