如何在mongodb中获取数组中对象的值?

2024-04-24 06:26:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在_id为1的文档中的数组中获取pricequantity为3的对象

{
   _id: 0,
   items: [
     { item_id: 43, quantity: 2, price: 10 },
     { item_id: 2, quantity: 1, price: 240 }
   ]
}
{
   _id: 1,
   items: [
     { item_id: 23, quantity: 3, price: 110 },
     { item_id: 103, quantity: 3, price: 5 },
     { item_id: 38, quantity: 2, price: 300 }
   ]
}
{
    _id: 2,
    items: [
       { item_id: 4, quantity: 1, price: 23 }
    ]
}
{
   _id: 3,
   items: [
     { item_id: 1241, quantity: 5, price: 13213 },
     { item_id: 4321, quantity: 6, price: 43214 },
     { item_id: 12341, quantity: 72, price: 12414 }
   ]
}
{
   _id: 4,
   items: [
     { item_id: 1241, quantity: 5, price: 13213 },
     { item_id: 4321, quantity: 6, price: 43214 },
     { item_id: 12341, quantity: 72, price: 12414 }
   ]
}
{
   _id: 5,
   items: [
     { item_id: 1241, quantity: 5, price: 13213 },
     { item_id: 4321, quantity: 6, price: 43214 },
     { item_id: 12341, quantity: 72, price: 12414 }
   ]
}

我该怎么办


Tags: 对象文档iditems数组itempricequantity