Please Help me, i want to show Vehicles(VehiclesDB) data using populate by select CityName(namaKota) from Schema Partner(RentalDB) in mongoodb, with NodeJs.. here my code
请帮助我,我想显示车辆(VehiclesDB)数据使用填充来自mongoodb中Schema Partner(RentalDB)的选择CityName(namaKota),使用NodeJs ..这里是我的代码
export class GetVehiclesbyKotaCommandHandler {
constructor(namaKota) {
return new Promise((resolve, reject) => {
VehiclesDB.find({"namaKota":namaKota}).populate({
path: 'mitraId',
model: 'RentalDB',
select: 'namaKota'
}).lean().then((dataVehicles)=>{
if(dataVehicles !== null){
resolve(dataVehicles);
} else {
reject (new NotFoundException('Couldn\'t find any Vehicles with id' + namaKota));
}
}).catch((errDataVehicles)=>{
reject(new CanNotGetVehiclesException(errDataVehicles.message));
});
});
}
}
}
my Vehicles Collection Structure
我的车辆收集结构
My Partner(Mitra) Collection Structure
我的合作伙伴(Mitra)收藏结构
But My Response is Succes and Don't Show Anything
但我的回应是成功的,不要表现出任何东西
{
"success": true,
"status": 200,
"message": "Successfully get kendaraan by mitraId!",
"error_code": null,
"data": []
}
}
1 个解决方案
#1
0
I am going to take a wild guess from looking at your images (better if you edit your question with your schemas) that there is a mismatch with type of mitraId
field in your Vehicles collection and _id
in your Partners collection.
我将通过查看您的图片(如果您使用您的模式编辑问题更好)进行疯狂猜测,即您的Vehicles集合中的mitraId字段类型与您的Partners集合中的_id不匹配。
The former is a String
whereas the latter is an ObjectID
. They need to be the same type in order to populate.
前者是String,后者是ObjectID。它们需要是相同的类型才能填充。
#1
0
I am going to take a wild guess from looking at your images (better if you edit your question with your schemas) that there is a mismatch with type of mitraId
field in your Vehicles collection and _id
in your Partners collection.
我将通过查看您的图片(如果您使用您的模式编辑问题更好)进行疯狂猜测,即您的Vehicles集合中的mitraId字段类型与您的Partners集合中的_id不匹配。
The former is a String
whereas the latter is an ObjectID
. They need to be the same type in order to populate.
前者是String,后者是ObjectID。它们需要是相同的类型才能填充。