必要なのは、Schemaメソッドから特定の「親」値を返すことです。
私は2つのスキーマを持っています:
var IP_Set = new Schema({
name: String
});
と
var Hash_IP = new Schema({
_ipset : {
type: ObjectId,
ref: 'IP_Set'
},
description : String
});
スキーマではHash_IP
、次のメソッドが必要です。
Hash_IP.methods.get_parent_name = function get_parent_name() {
return "parent_name";
};
だから私が走るとき:
var hash_ip = new Hash_IP(i);
console.log(hash_ip.get_parent_name())
関連するインスタンスのIP_Set
名前の値を取得できます。Hash_IP
これまでのところ、次の定義がありますが、名前を返すことができません。
Hash_IP.methods.get_parent_name = function get_parent_name() {
this.model('Hash_IP').findOne({ _ipset: this._ipset })
.populate('_ipset', ['name'])
.exec(function (error, doc) {
console.log(doc._ipset.name);
});
};
私はもう試した:
Hash_IP.methods.get_parent_name = function get_parent_name() {
this.model('Hash_IP').findOne({ _ipset: this._ipset })
.populate('_ipset', ['name'])
.exec(function (error, doc) {
return doc._ipset.name;
});
};
結果なし。
助けてくれてありがとう。