Why using new person and .save(). Why not person.create()?

Tell us what’s happening:
The question I have is why are we using .save() . Why not using only .create ?
The question proper is what is difference between using . create an d.save?

Am kinda confused.
Your code so far

var person = new Person( {name: 'Tany', age: 23, favouriteFoods: ['tuna', 'bread'] }); person.save((err, data)=>{ if (err) return done(err) return done(null, data) })

person.create( {name: 'Tany', age: 23, favouriteFoods: ['tuna', 'bread'] },(err, data)=>{ if (err){ handle error }else{ blah blah blah } }))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36.

Challenge: Create and Save a Record of a Model

Link to the challenge:

Both basically do the same job, creates database document.
Both trigger the save() middleware

  • Model.create() its more generic, you call it directly from your Model class.
  • Model.prototype.save() , you call it from an instance of that Model.
    const test = new Test();

Its your personal preference. Its up to you to call whichever you like.


:heartbeat: :heartbeat: