Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
Probleme post from node.js to mongodb

I'm pretty new to nodeJS and i'm trying to send data from a register form to mongodb but I apparently made a mistake using the post method, since i can't visualize it on postman

const express = require('express');
const router = express.Router();
const registerData = require('./models/registerData');

router.get('/', (req, res) => {
  res;
  render('index', { title: 'Accueil', description: 'Ceci est la page index' });
});

router.post('/', (req, res) => {
  var rData = new registerData();
  rData.firstName = req.body.firstName;
  rData.lastName = req.body.lastName;
  rData.date = req.body.date;
  rData.email = req.body.email;
  rData.password = req.body.password;
  rData.save((err) => {
    if (err) {
      res.render('index', {
        title: 'Accueil',
        description: "Une erreur s'est produite",
      });
    }
    res.render('index', {
      title: 'Accueil',
      description: 'registerData a été sauvegardé',
    });
  });
  res.redirect('/');
});

module.exports = router;

here is the file where i declare my schema

const mongoose = require('mongoose'),
  Schema = mongoose.Schema;

const registerDataSchema = new Schema({
  firstName: String,
  lastName: String,
  date: String,
  email: String,
  password: String,
});

const registerData = mongoose.model('registerData', registerDataSchema);

module.exports = registerData;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this

router.post('/', (req, res) => {

    const data = {
        firstName: req.body.firstName,
        lastName: req.body.lastName,
        date: req.body.date,
        email: req.body.email,
        password: req.body.password
    };
    rData = new registerData(data);
    rData.save((err) => {
        if (err) {
            res.render('index', {
                title: 'Accueil',
                description: "Une erreur s'est produite",
            });
        }
        res.render('index', {
            title: 'Accueil',
            description: 'registerData a été sauvegardé',
        });
    });
    res.redirect('/');
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!