我在跟踪
Brad Traversy's
post
请求路由
localhost:5000/api/profile
发送后
post request
数据为
handle,status,skills
如果是我的集合中的字段,则返回error
skills field required
.
skills是从用户输入发送的字符串数组。
当我检查的时候
collection-profile
则不创建,并且只有一个集合显示为主集合
user
,
我遵循教程中的每一行代码,但遇到错误,我想
Profile collection
我的
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,但没用。
repo link
.