Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating methods to update & save documents with mongoose?

After checking out the official documentation, I am still not sure on how to create methods for use within mongoose to create & update documents.

So how can I do this?

I have something like this in mind:

mySchema.statics.insertSomething = function insertSomething () {     return this.insert(() ? } 
like image 742
Industrial Avatar asked Jan 24 '12 13:01

Industrial


People also ask

What is update method in applet?

Applet class is a final method used whenever we want to call update method along with the call to paint method; call to update method clears the current window, performs an update, and afterwards calls paint method.

What does the update method do in Java?

Java Update is a feature that keeps your Windows computer up-to-date with the latest Java releases. When you have auto update enabled, your system periodically checks for new versions of Java. When a new version is found we ask your permission to upgrade your Java installation.


1 Answers

From inside a static method, you can also create a new document by doing :

schema.statics.createUser = function(callback) {   var user = new this();   user.phone_number = "jgkdlajgkldas";   user.save(callback); }; 
like image 55
hydrozen Avatar answered Sep 24 '22 12:09

hydrozen