What I try to do is something like this:
A_Schema.statics.init = function init() {
A_Schema.find({}, {}, {
}, function (error, docs) {
if (!error) {
console.log('There is no error.');
}
else {
console.log(error);
}
});
};
I mean, using the find method of the A_Schema model but it keeps crashing.
I suppose that is because the inner A_Schema is must be a properly defined Model and not a Schema, but I don't know how to do it.
I already tried:
A_Schema.statics.init = function init() {
mongoose.model('A_Schema', A_Schema).find({}, {}, {
}, function (error, docs) {
if (!error) {
console.log('There is no error.');
}
else {
console.log(error);
}
});
};
and
A_Schema.statics.init = function init() {
mongoose.model('A_Schema').find({}, {}, {
}, function (error, docs) {
if (!error) {
console.log('There is no error.');
}
else {
console.log(error);
}
});
};
but it keep crashing.
Can you help me?
Thanks in advance
Diosney
Sorry, it seems that I overlook the mongoose documentation.
At mongoose documentation can be see the example:
animalSchema.statics.findByName = function (name, cb) {
this.find({ name: new RegExp(name, 'i') }, cb);
}
So, inside a static the this reference must be used instead of the named model.