Я следую курсу Брэда Траверси по разработке стека MERN и в 4-м разделе не могу сделать post
запрос на маршрут localhost:5000/api/profile
,
после отправки post request
с данными как handle,status,skills
, которые являются полями в моей коллекции, он возвращает ошибку skills field required
.
skills — это массив строк, отправленных пользователем.
когда я проверил, collection-profile
создан или нет, он не создан, и только одна коллекция отображается как основная коллекция user
,
Я следил за каждой строкой кода в учебнике, но получил ошибку, я хотел, чтобы Profile collection
было создано на удаленном mlab mongodb,
код моей модели profile
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
// Create Schema
const ProfileSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: "users"
},
handle: {
type: String,
required: true,
max: 40
},
company: {
type: String
},
website: {
type: String
},
location: {
type: String
},
status: {
type: String,
required: true
},
skills: {
type: [String],
required: true
},
bio: {
type: String
},
githubusername: {
type: String
},
experience: [
{
title: {
type: String,
required: true
},
company: {
type: String,
required: true
},
location: {
type: String
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}
],
education: [
{
school: {
type: String,
required: true
},
degree: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}
],
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
},
date: {
type: Date,
default: Date.now
}
});
module.exports = Profile = mongoose.model("profile", ProfileSchema);
используя модуль validator.js
, я проверяю поля ввода,
if (Validator.isEmpty(data.skills)) {
errors.skills = "Skills field is required";
}
Итак, я не могу найти, почему именно я не могу найти новую коллекцию в профиле?
Я пытался использовать mongodb-local, но это не помогло.
мой Github ссылка на репозиторий.
profile
, но ошибка сохраняется, какskills field is necessory
, хотя я отправил массив значений, разделенных запятой. - person GD- Ganesh Deshmukh   schedule 05.09.2018