Difference between insert new data using instance of new object or using .create

324
April 10, 2017, at 11:39 AM

What's the diference between these two ways?

Example:

var user = new User({
    user.name = "Blabla",
    user.password = "blabla"
});

User.create({name:req.body.blabla, password:req.body.blablabla},callback func)
Answer 1

The first one is simply instantiating a new user instance before saving to the database.

var user = new User({
  user.name = "Blabla",
  user.password = "blabla"
});

You'll need to save it to the database like this

user.save(callback)

However, the second implementation has save as part of its internal implementation. So, it basically instantiate the User model and save the new instance

Rent Charter Buses Company
READ ALSO
OpenCV accident detection with nodeJS (Intel Edison)

OpenCV accident detection with nodeJS (Intel Edison)

I have a project where I have to use Opencv camera to detect car accidents, using nodeJs or java code or pyhton to monitor dataI also have to make sure the camera and the board (Intel Edison) both are configured to same IP Address

390