如何通过关系id从mongosNode js中的用户表中获取数据



我有一个订单表
Mongo db版本是3.0.15
订单表有这些列

{
"status": "new",
"_id": "5fd320a8b3d5133c8bf00c4a",
"categoryId": "5fb2e20f5ea2aa2d15cca1ef",
"specialization": "Tesst",
"requestedBy": "5fd232ecd7ba652c3a85f818",
"vendorId": "5fa908773410d8591aa9f550",
"updated_at": 1607671976182,
"created_at": 1607671976182,
},

请求的属于第二表用户
我想从用户表用户名用户地址获取用户详细信息

在用户表中,我有这些列

{
"_id": "5fd232ecd7ba652c3a85f818",
"phone": "1234567890",
"otp"  : "123456",
"progress_pictures": [],
"createdAt": "2020-12-10T14:38:36.045Z",
"updatedAt": "2020-12-10T14:39:35.127Z",

}

我如何获取任何人都知道的数据

Order.find(
{
status  : status
},
{
}
).exec();

这是我的订单邀请查询这是工作查找只获取订单表数据

我使用populate找到了解决方案

Order.find(
{
status  : status
},
{
}
).populate([
{
path: 'requestedBy', // in order table user ref id 
select : 'name phone user_address'
},{
path : 'vendorId', // in order table vendor ref id 
select : 'vendorName vendorMobile vendorAddress vendorBusinessName'
}]).exec();
----------------------- RESPONSE -----------------------
{
"status": "new",
"_id": "5fd320a8b3d5133c8bf00c4a",
"categoryId": "5fb2e20f5ea2aa2d15cca1ef",
"specialization": "Tesst",
"requestedBy": {
"user_address": [],
"name" : "nikhil",
"_id": "5fd232ecd7ba652c3a85f818",
"phone": "1234567890"
},
"vendorId": {
"_id": "5fa908773410d8591aa9f550",
"vendorMobile": "1234567890",
"vendorAddress" : "demo address",
"vendorBusinessName" : "testing hub",
"vendorName": "KL"
},
"updated_at": 1607671976182,
"created_at": 1607671976182,
},

相关内容

  • 没有找到相关文章