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)
答案 0 :(得分:0)
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