How do you perform CRUD with Mongoose?

MongoDB and Mongoose · Freshers

Model answer

Create: Model.create(data). Read: Model.find(filter), findById(id), findOne(filter). Update: findByIdAndUpdate(id, data, { new: true, runValidators: true }). Delete: findByIdAndDelete(id). Always validate input and check for null results to return 404.

Learn this topic

Connect Express to MongoDB with Mongoose in the course MERN Stack Full Course: MongoDB, Express, React and Node.js.

Sign in to add your own answer.

More questions