下面是运行以下查询时得到的响应
Order.find().then((find) => {
res.json(find);
});
[
{
"isPrime":false,
"orderStatus":"Pending",
"orderTotal":"27.98",
"orderType":"x",
"subOrderId":"x",
"children":[
"5bd105dc1b85bc2faca27603",
"5bd105dd1b85bc2faca2760b",
"5bd105dd1b85bc2faca27613"
],
"_id":"x",
"deliveryDate":"x",
"orderChannel":"xx",
"orderDate":"xZ",
"orderLabel":"NA",
"shipDate":"x",
"__v":0
},
]
如何在同一查询中获得有关子项的信息,或者在其他查询中如何获得子项的信息?
答案 0 :(得分:0)
使其与以下代码一起使用 子级1到3是子级文档。也必须更改我的架构
来自
children:[{type:Schema.ObjectId, ref:"ONLINE_ORDER_ITEMS"} , {type:Schema.ObjectId, ref:"ONLINE_ORDER_CUSTOMERS"}, {type:Schema.ObjectId, ref:"ONLINE_ORDER_SHIPMENTS"}]
到
children1:[{type:Schema.ObjectId, ref:"ONLINE_ORDER_ITEMS"}],
children2:[{type:Schema.ObjectId, ref:"ONLINE_ORDER_CUSTOMERS"}],
children3:[{type:Schema.ObjectId, ref:"ONLINE_ORDER_SHIPMENTS"}]
Order.find({ 'orderStatus': typeFlag}).populate('children1').populate('children2').populate('children3').then((find) => {
res.json(find);
});