I am trying to convert my MongoDB database of MERN project to MySQL Database. Can someone please help me with the steps on how to change the steps in my project backend. I stored cors.js and env.js in utils folder and below are the code : env.js
module.exports = {
mongo: 'mongodb+srv://admin:[email protected]/sp?retryWrites=true'
}
cors.js
module.exports = function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'DELETE, PUT, GET, POST');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Headers","*")
next();
}
connection.js
const url = require('../utils/env');
const mongoose = require('mongoose');
mongoose.connect(url.mongo);
mongoose.connection.on('open',()=>{
console.log("connected to database");
})
module.exports = mongoose;
userschema.js
const mongoose = require('../connection');
const Schema = mongoose.Schema;
const UserSchema = new Schema ({
username: {type: String,required: true,unique: true},
email: {type: String, required: true,unique:true},
password: {type: String, required: true},
})
const userModel = mongoose.model('user',UserSchema);
module.exports = userModel;
Please help me with any useful links or anything related articles for understanding as I am trying to learn as a beginner.