Node.js – Creating methods to update & save documents with mongoose

expressmethodsmongodbmongoosenode.js

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(() ?
}

Best Solution

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);
};