私は1つのメインコレクションと1つのコレクションを持っています。コードは次のようになります。モンゴース人口が空のオブジェクトを返す
// Ref schema
const onlineSchema = mongoose.Schema({
_id: {
type: Number,
ref: 'Player',
unique: true
}
}, {
timestamps: true
});
//main schema
const playerSchema = mongoose.Schema({
_id: { // User ID
type: Number,
required: true,
unique: true,
default: 0
},
firstname: {
type: String
},
name: {
type: String,
required: true
},
lastname: {
type: String
},
barfoo: {
type: Boolean
}
...
})
私はこのコードを移入:
var baz = bar;
...
Online.find().populate({
path: '_id',
match: {
[ baz + 'foo']: true
}
}).exec(function(err, online) {
if (err) {
winston.error(err);
} else {
winston.error(util.inspect(online, {
showHidden: false,
depth: null
}));
}
});
オンラインで10個の要素とはわずか7試合[ baz + 'foo']: true
がある場合は、私は7つの適切な配列とこのようになり3空の配列を取得します:
{ updatedAt: 2016-12-23T18:00:32.725Z,
createdAt: 2016-12-23T18:00:32.725Z,
_id: null,
__v: 0 },
なぜこのようなことが起こり、最終結果をフィルタリングして一致する要素のみを表示するのですか?
私は結果を得た後にnull配列を削除するためにfilterを使うことができますが、最初にヌル配列を渡すことを避ける方法を知りたいと思います。
参照として_idを使用するまで、Populateは正しく動作しませんでした。 – Trax