数据未发布在带有快递和翡翠的猫鼬上
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据未发布在带有快递和翡翠的猫鼬上相关的知识,希望对你有一定的参考价值。
我的注册表数据未发布在猫鼬数据库中,这是我的代码
我的代码在从数据库中获取数据但未发布代码时有效请帮助我[]
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
我的注册表数据未发布在猫鼬数据库上,这是我的代码,当我从数据库中获取数据时,我的代码正在工作,但其未发布代码,请帮助我app.set('views',...
答案
您未正确使用multer处理表单。
您需要将属性multipart / form-data添加到表单,并确保在应用程序实例中添加一个正文解析器:
以上是关于数据未发布在带有快递和翡翠的猫鼬上的主要内容,如果未能解决你的问题,请参考以下文章