Данные моей регистрационной формы не публикуются в базе данных mon goose Вот мой код
мой код работает, когда я получаю данные из моей базы данных, но код не публикуется, пожалуйста, помогите мне, ребята
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false }));
**mongoose connection**
mongoose.connect("mongodb://localhost:27017/change")
.then(() => console.log('Connected to MongoDB ...'))
.catch(err => console.error('Could not connect to MongoDB....',err));
Схема
// Schema
const courseSchema = new mongoose.Schema({
firstName: String,
fName: String,
add1: String,
add2: String,
city: String,
province: String,
zip:Number,
country: String,
age: Number,
gender: String,
color:String,
Height:Number,
mTongue:String,
moi:String,
disability:String,
religion:String,
mHealth:String,
name:String,
contact:Number,
add3:String,
add4:String,
city1:String,
state:String,
postal:String,
country1:String,
RTC:String,
email: String,
profileimage:{
type: String
},
date: { type: Date, default: Date.now},
isPublished: Boolean
});`
Маршрутизация
app.post("/addname",upload.single('profileimage'), (req, res) => {
const myData = new User(req.body);
myData.save()
.then(item => {
res.redirect('/');
})
.catch(err => {
res.status(400).send("Unable to save to database");
});
** Нефритовый код **
Вот код моей регистрационной формы
> `form(method='post', action='/addname')
hr
.row
.col-sm-6
.form-group
label Name
input.form-control(type='text', name='firstName', placeholder='Enter Name')
.col-sm-6
.form-group
label Father Name
input.form-control(type='text', name='fName', placeholder='Enter Name', required)
.col-sm-6
.form-group
label Address Line 1
input.form-control(type='text', name='add1', placeholder='Enter Address Line 1', required)
.col-sm-6
.form-group
label Address Line 2
input.form-control(type='text', name='add2', placeholder='Enter Address Line 2', required)
.col-sm-6
.form-group
label City
input.form-control(type='text', name='city', placeholder='Enter City', required)
.col-sm-6
.form-group
label State/Province/Region
select.form-control(name='state', id='' .dropdown-menu , required)
each val in ['Sindh' , 'Punjab' , 'KPK' ,'Balochistan', 'Gilgit-Baltistan' , 'AJK', 'Islamabad']
option=val
.col-sm-6
.form-group
label Postal / Zip Code
input.form-control(type='text', name='zip', placeholder='Enter Postal / Zip Code', required)
.col-sm-6
.form-group
label Country
input.form-control(type='text', name='country', placeholder='Country', required)
.col-sm-6
.form-group
label Age
input.form-control(type='number', name='age' , placeholder='Age', required)
.col-sm-6
.form-group
label Gender
select.form-control(name='gender', id='' .dropdown-menu , required)
each val in ['Male' , 'Female' , 'Other']
option=val
.col-sm-6
.form-group
label Color
select.form-control(name='color', id='', required .dropdown-menu)
each val in ['Fair' , 'Brown' , 'Dark' , 'Black' , 'Wheatish']
option=val
.col-sm-6
.form-group
label Height
input.form-control(type='text', name='height', placeholder='Enter Height', required)
.col-sm-6
.form-group
label Mother Tongue
select.form-control(name='mTongue', id='', required .dropdown-menu)
each val in ['Sindhi' , 'Balochi' , 'Urdu' , 'Punjabi' , 'Phusto' , 'Other']
option=val
.col-sm-6
.form-group
label Marks of Identification
input.form-control(type='text', name='moi', placeholder='Enter Marks of Identification ', required)
.col-sm-6
.form-group
label Disability if any
input.form-control(type='text', name='disability', placeholder='Disability if any', required)
.col-sm-6
.form-group
label Religion
input.form-control(type='text', name='religion', placeholder='Religion', required)
.col-sm-6
.form-group
label Mental Helth
input.form-control(type='text', name='mHealth', placeholder='Enter Mental Helth', required)
//- .col-sm-6
//- .form-group
//- label Missing Person Image
//- input.form-control(name='profileimage', type='file')
hr
h2 Information Details
.row
.col-sm-6
.form-group
label Name
input.form-control(type='text', name='name', placeholder='Enter Name', required)
.col-sm-6
.form-group
label Contact No
input.form-control(type='text', name='contact', placeholder='Enter Contact NO', required)
.col-sm-6
.form-group
label Address Line 1
input.form-control(type='text', name='add3', placeholder='Enter Address Line 1', required)
.col-sm-6
.form-group
label Address Line 2
input.form-control(type='text', name='add4', placeholder='Enter Address Line 2', required)
.col-sm-6
.form-group
label City
input.form-control(type='text', name='city1', placeholder='Enter City', required)
.col-sm-6
.form-group
label State/Province/Region
select.form-control(name='state', id='' .dropdown-menu , required)
each val in ['Sindh' , 'Punjab' , 'KPK' ,'Balochistan', 'Gilgit-Baltistan' , 'AJK', 'Islamabad']
option=val
.col-sm-6
.form-group
label Postal / Zip Code
input.form-control(type='text', name='postal', placeholder='Enter Postal / Zip Code', required)
.col-sm-6
.form-group
label Country
input.form-control(type='text', name='country1', placeholder='Country', required)
.col-sm-6
.form-group
label Relation to the child
input.form-control(type='text', name='RTC', placeholder='Relation to the child', required)
.col-sm-6
.form-group
label Email
input.form-control(type='email', name='email', id="exampleInputEmail1" , placeholder='Email', required)
.col-sm-6
.form-group
input.btn.btn-primary(type='submit', name='submit',value='Submit')`
[When i posted data ][1]
Когда я публикую данные, мои данные не публикуются в базе данных и выдают ошибку, но если я нахожу данные, показанные на моей странице, они показывают данные
[1]: https://i.stack.imgur.com/pnGvC.png