1

I am very new to nodejs and trying to create a registration API using nodejs, I search for it and got some code but the problem is developer is using MongoDB but I am using MYSQL. So my question is how to create a schema in MYSQL using nodejs, I got the code where developer created the schema in MongoDB.

Here is the code:

const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const userSchema = new Schema({
    email: String,
    password: String,
});

module.exports = mongoose.model('user', userSchema, 'users');

Also Why we need schema in the first place can't I just create table in my database manually and Insert data using Insert Query.

Thanks.

2
  • Go through it stackoverflow.com/questions/34039489/… hope it will help you Commented Feb 5, 2020 at 6:02
  • You are looking for a relational ORM. For example Objection.js Commented Feb 5, 2020 at 8:30

1 Answer 1

1

You don´t need a specific schema if you are using mySQL. The database itself has a schema and won´t give you the chance to store malformed data if configured correctly. Mongoose provides a schema for mongoDB, because mongoDB is schema-less. You can store any kind of data and you won´t get an error back if malformed data was stored. But of course if you are using TypeScript, you can build an interface or a class and validate data before storing without the use of any kind of third-party package

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.