I have Mongoose
schema and a model:
var MyClientSchema = new mongoose.Schema({
fist_name: {
type: String
},
phone_number: {
type: String
}
});
var MyClient = mongoose.model('MyClient', MyClientSchema);
How should I document (using JSDoc) MyClient
and/or MyClientSchema
to get tab-completion and type suggestions from WebStorm
for both methods inherited from mongoose.model
like remove, findOne, find
- and inherited from schema - like phone_number and first_name
?
A Mongoose schema defines the structure of the document, default values, validators, etc., whereas a Mongoose model provides an interface to the database for creating, querying, updating, deleting records, etc.
In Mongoose, a "document" generally means an instance of a model. You should not have to create an instance of the Document class without going through a model.
An instance of a model is called a document. Models are responsible for creating and reading documents from the underlying MongoDB database.
The mongoose. model() function of the mongoose module is used to create a collection of a particular database of MongoDB.
I found @class
(or its synonym @constructor
) works for schema properties:
/**
* @class MyClient
*/
var MyClientSchema = new mongoose.Schema({
fist_name: {
type: String
},
phone_number: {
type: String
}
});
var MyClient = mongoose.model('MyClient', MyClientSchema);
The @alias
works for methods declared the old way:
/**
* @alias MyClient.prototype.getDescription
*/
MyClientSchema.method('getDescription', function () {
return this.first_name + " " + this.phone_number;
});
However, you can mark all methods as part of MyClient
at once if you use the new way of declaring methods:
/**
* @class MyClient
* @mixes {MyClientSchema.methods}
*/
var MyClientSchema = new mongoose.Schema({ ...
/** @mixin */
MyClientSchema.methods;
MyClientSchema.methods.getDescription = function () {
return this.first_name + " " + this.phone_number;
};
All the above tested in latest WebStorm version (2018.2). It works.
Things which do not work:
.find()
or .save()
.methods
syntax highlight works but code completion doesn't.Updates are welcome!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With