How to save a dice with mongosis

Asked

Viewed 39 times

-2

Good afternoon.

I would like to know how to save a data in mongodb, because I tried a method and it worked, now I’m trying the same in another function and it’s not working.

Thanks for the help

inserir a descrição da imagem aqui

  • save is insert new record or update another record?

  • Include the code in the body of the question and not in a print for easy searching.

2 answers

0

you can use the methods findOneAndUpdate() or findByIdAndUpdate() to search for a field and change it

const categoria = {name: req.body.name, ...}

categorias.findOneAndUpdate({id: req.body.id}, categoria )

More in : Mongoose queries

  • Thank you so much for your help.

0

the . Lean() method after . findOne() does not allow you to use . save() and also you have a comma after the name

categorias.nome = req.body.nome,

I believe that after these modifications your code will work

  • 1

    Thank you very much, that solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.