0

私がやろうとしていることは次のようなものです:

A_Schema.statics.init = function init() {
    A_Schema.find({}, {}, {
    }, function (error, docs) {
        if (!error) {
            console.log('There is no error.');
        }
        else {
            console.log(error);
        }
    });
};

つまり、A_Schemaモデルの find メソッドを使用していますが、クラッシュし続けます。

内部A_Schemaはスキーマではなく適切に定義されたモデルでなければならないためだと思いますが、その方法がわかりません。

私はすでに試しました:

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

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

しかし、それはクラッシュし続けます。

手伝って頂けますか?

前もって感謝します

ディオスニー

4

1 に答える 1

0

申し訳ありませんが、mongooseドキュメントを見落としているようです。

マングースのドキュメントでは、例を参照できます。

animalSchema.statics.findByName = function (name, cb) {
  this.find({ name: new RegExp(name, 'i') }, cb);
}

そのため、 static 内thisでは、名前付きモデルの代わりに参照を使用する必要があります。

于 2012-12-10T04:27:23.473 に答える