I am currently facing a challenge where I need to migrate my app's database from mongoDB to mysql. The application was initially developed using node.js, but I encountered an issue with the "Create table" query while attempting the conversion process.
var setting = new MongoCon.Schema({
site: {
type: Object,
default: {
someData: {
lengthMsgBc: 250,
likeUpPic: 10,
},
title: "",
walllikes: {
likeUpPic: 10,
},
},
},
dro3: {
type: Array,
default: [
"1604251747557.gif",
"1604251842627.gif",
"1604251846871.gif",
],
},
});
After trying to convert the code snippet above to SQL, I encountered errors in the resulting query.
mysqlCon.query('CREATE TABLE al3ochek_settings (_id INT NOT NULL AUTO_INCREMENT, site VARCHAR(255) DEFAULT "{"someData":{"lengthMsgBc":250,"likeUpPic":10},"title":"","walllikes":{"likeUpPic":10}}", dro3 VARCHAR(255) DEFAULT "["1604251747557.gif","1604251842627.gif","1604251846871.gif"]", PRIMARY KEY (_id) )', err => {
if (err) throw err;
console.log("Table al3ochek_settings created!")
})
The problematic part of the SQL query arises when using JSON.stringify to save an object in the "site" column, resulting in an error due to a specific character combination.
"{" "["
If you have a solution to this issue or any suggestions on how it can be resolved, your assistance would be greatly appreciated.