Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
POST one data value in 2 models Json, mongoDB, MongoDB

I created a code that has 2 functions;

module.exports.registerAccount = (reqBody) => {

let newAccount = new User({
    firstName : reqBody.firstName,
    lastName : reqBody.lastName,
    email : reqBody.email,
    mobileNum : reqBody.mobileNum,
    password : bcrypt.hashSync(reqBody.password, 10)
})

return await newAccount.save().then((account, error) =>{
    if(error){
        return false;
    }
    else{
        return true;
    }
})

let newCustomer = new Order ({
    FirstName : reqBody.firstName,
    LastName : reqBody.lastName,
    MobileNum : reqBody.mobileNum
})

return await newCustomer.save().then((customer, error) =>{
    if(error){
        return false;
    }
    else{
        return true;
    }
})
}

The newAccount is for the user model and the newCustomer is for the order model, I tried the codes and there's no error but the newCustomer is not saving in its model. I also tried to swap the position of the two model and the result is also swap. is there a way to make both of it work in one go? can I have some tips?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found the solution;

return newAccount.save() && newCustomer.save().then((account, error) =>{
    if(error){
        return false;
    }
    else{
        return true;
    }
})

since that only one return statement is working I used && in between newAccount and newCustomer.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda