mongodb - What is the difference between Model#remove and Model.remove in Mongoose? -


in mongoose api docs, there model#remove, , there model.remove.

can explain, in layman terms, difference between these two? appears accept different parameter(s). , why 1 using dot , other using hash? need clearer explanation besides 1 in api docs.

model#remove instance method, model.remove class method.

in other words, have model called users. remove collection belongs model, have 2 options (this example bit contrived):

users.findone(condition, function(err, user) {   if (err) throw err;   user.remove(function(err) {     if (err) throw err;     // user removed   }); }); 

this uses model#remove: have instance of model stored in user, , remove instance database calling remove method on instance.

the other option:

users.remove(cond, function(err) {   if (err) throw err;   // user_s_ matching cond have been removed }); 

basically, model#remove used remove single document instance have, , model.remove used remove possibly list of documents match particular condition, or document don't first want retrieve database.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -