Cộng đồng Hỏi & Đáp của Inflearn
post 전송 에러 질문드립니다
Viết
·
355
0
index.js
const express = require("express"); //express import
const app = express();
const port = 5006;
const bodyParser = require("body-parser");
const { User } = require("./models/User");
//applicatioin /x-www-form -url encoded
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const mongoose = require("mongoose");
mongoose
.connect(
"mongodb+srv://euan:abcd1234@boilerplate.tywi2.mongodb.net/?retryWrites=true&w=majority ",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
}
)
.then(() => console.log("mongo db is connected.."))
.catch((err) => console.log(err));
app.get("/", (req, res) => {
res.send("Hello World122!");
});
app.post("/register", (req, res) => {
const user = new User(req.body);
user.save((err, userInfo) => {
if (err) return res.json({ success: false, err });
return res.status(200).json({
success: ture,
});
});
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
user.js
const mongoose = require("mongoose");
const userSchema = mongoose.Schema({
name: {
type: String,
maxlength: 500,
},
email: {
type: String,
trim: true,
unique: 1,
},
password: {
type: String,
minlength: 5,
},
lastname: {
type: String,
maxlength: 50,
},
role: {
type: Number,
default: 0,
},
image: String,
token: {
type: String,
},
tokenExp: {
type: Number,
},
});
const User = mongoose.model("User", userSchema);
module.exports = { User };
------------------------------------------------------------------
{
"success": false,
"err": {
"driver": true,
"name": "MongoError",
"index": 0,
"code": 11000,
"keyPattern": {
"email": 1
},
"keyValue": {
"email": "maplestory1419@gmail.com"
}
}
}
서버확인하였는데 이런식으로 에러가 나옵니다. name에 에러가 있는것 가은데 혼자힘으로 해결이 힘들어 질문드립니다!
감사합니다!
몽고db연결도 확인하였습니다.
자꾸 질문드려서 죄송하네요 ㅠㅠ console 창에도 에러가 없으니 뭐가문제인지 단서를 찾을수가 없습니다 ㅠㅠ
ps강의 정말감사합니다 ㅠ커피라도 대접해드리고싶네용
nodejsreact
Câu trả lời 3
1
혹시라도 이런 오류가 뜨는분들 보시라고 답글 달아놓을게요
email 속성에 unique가 있어서 뜨는것으로 확인됩니다
회원가입이 되어있는데 또 똑같은 이메일로 회원가입을 해서 뜨는 오류메시지 입니다
0
0
John Ahn
Người chia sẻ kiến thức
안녕하세요
현재 이 상황이 어떤 요청을 할때 나오는 것인가요 ? 회원 가입 할때 인가요 ? 아니면 로그인 할 때 인가요 ~ ?





