I have problem with find full model in Mongoose populate.
2 models mongoose:
//first
var CardSchema = new Schema({
userId: String,
payment: { type: Number, ref: 'Payment' }
});
module.exports = mongoose.model('MedicalCard', CardSchema);
//second
var PaymentSchema = new Schema({
_id: Schema.Types.ObjectId,
cost: String,
});
module.exports = mongoose.model('Payment', PaymentSchema);
And I want find all carts certain user:
CardModel.find({ userId: id}).populate('payment').exec( function (err, data) {
if (err) {
//error
}
if (data) {
console.log(data);
}
});
But for me return result:
[
{
"_id": "56ed9993a5c9067a21edec69",
"userId": "56eaccec930c15cf245a86a1",
"payment": null,
"__v": 0
},
{
"_id": "56ed99a7a5c9067a21edec6d",
"userId": "56eaccec930c15cf245a86a1",
"payment": null,
"__v": 0
}
]
But Mongotron return for me correct result:
[
{
"_id": ObjectId('56ed99a7a5c9067a21edec6d'),
"userId": 56eaccec930c15cf245a86a1,
"payment": ObjectId('56ed99a7a5c9067a21edec6a')
},
{
"_id": ObjectId('56ed9993a5c9067a21edec69'),
"userId": "56eaccec930c15cf245a86a1",
"payment": ObjectId('56ed99a7a5c9067a21edec6c')
}
]
what could be the problem? And how fix it?
P.S. I've changed payment: { type: Number, ref: 'Payment' } type to ObjectId, but problem not solved