Mongoose static methods autocompletion in WebStorm

When doing the following in WebStorm, I cannot get autocompletion when importing a mongoose model and trying to use a static method on the schema.

In one file I have my Mongoose schema defined with static methods:

 userSchema.statics.saveUser = function(callback){
        var user = new this();;

And in another file I try to use these methods and I don't get autocompletion...

var User = require('../models/user.js');
User.saveUser(function(err, result) {

Whereas if I would type User.statics.saveUser(... I would get autocompletion.

Do you know about a workaround ? Thanks.

Comment actions Permalink

please can you provide the whole User module definition?

Comment actions Permalink
// grab the things we need
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var async = require('async');
var config = require('../config/config');

// create a schema
var IdConnectionSchema = new Schema({
name: String, // SQL(Live)

// on every save, add the date
IdConnectionSchema.pre('save', function(next) {
// get the current date
var currentDate = new Date();

// change the updated_at field to current date
this.updated_at = currentDate;

// if created_at doesn't exist, add to that field
if (!this.created_at)
this.created_at = currentDate;


// Model level operations.
// Could define this method in the controller, but not the right place.
IdConnectionSchema.statics.doSomething = function(doSomethingCallback) {
// do whatever

var IDConnection = mongoose.model('ID_Connection', IdConnectionSchema);

// make this available to our users in our Node applications
module.exports = IDConnection;
Comment actions Permalink

I would like the doSomething method be in autocomplete whenever I do 

var IdConnection = require('./idConnectionModel');


c.f: (statics section)

Comment actions Permalink

I can see 2 problems here:

- WebStorm knows nothing about Mongoose 'methods' and 'statics' objects, it has no way to understand that these objects are used to create custom instance and static methods for Models. Understanding these constructions requires providing special support for Mongoose

- completion doesn't work when re-exporting module instance (, so neither predefined nor custom methods are available in completion if Model is defined as a separate module

Comment actions Permalink

Any chance you could implement special support for Mongoose ? 
It is a VERY popular module for Node.JS and I'm sure it could benefit lots of developers and this way you could acquire lots of new customers which feel NodeJS support as of today is not good enough...

Thanks for your help.

Comment actions Permalink

Anyway thanks for your help and swift response.

Can you think of any workaround in the meantime ?

Comment actions Permalink

You can try using JSDoc here... for example:

var userSchema = new Schema({
name: String,
password: String
* @memberOf User#
userSchema.methods.findSimilarNames = function(cb) {

* @memberOf User
userSchema.statics.findByName = function(name, cb) {


/** @class User */
var User = mongoose.model('User', userSchema);

module.exports = User;
Comment actions Permalink

Thanks a lot, this is of great help!!! 
Do you know if you could implement seemless integration of Mongoose package inside Jetbrains suite

Comment actions Permalink

Please feel free to file a request for this feature to youtrack,

Comment actions Permalink

Go to Preferences . Languages&Frameworks . Javascript . Libraries . Download

scroll down to mongoose, select it, press "Download and install".

In case it isn't obvious, what you're doing is installing the typescript definitions for typescript code to understand mongoose.  Webstorm can use these to understand plain JavaScript, too.  

Comment actions Permalink


Done that!


This is still an issue and I'm trying to reproduce:


const mongoose = require('mongoose');

const UserSchema = mongoose.Schema({
name: {type: String}

const User = module.exports = mongoose.model('User', UserSchema);

module.exports.getByID = function (id) {

return User.findById(id)




Whereas when i do this:

const User = module.exports.UserModel = mongoose.model('User', UserSchema);

I do not get 'direct' autocompletion, but at least Webstorm doesn't complain about 'unresolved variable':

In VS Code i.e it does work. Can we get a fix please? I DO LOVE JETBRAINS! :)



Comment actions Permalink

this issue is tracked as, please follow it for updates


Please sign in to leave a comment.