【问题标题】:How to get particular fields in array of objects mongodb如何获取对象数组中的特定字段mongodb
【发布时间】:2019-08-12 07:02:16
【问题描述】:

我只需要上图中每个对象中的 path。 我试过这样的事情

userRouter.post('/delete_products',function(req,res){
Collections.product.find({ "_id": req.body.id }, { "pimages.path": "1" },function(err,result){
    if(err)
    res.send(err)
    else
    res.send(result)
    const map=result.map(user=>user.pimages.map(user=>user.path))
    console.log(map);
})

})

[ [ '1552640783_mixer front.jpg', '1552640783_mixer back.jpg' ] ]

我是这样的。我期待以对象形式的数组输出

[{'1552640783_mixer front.jpg'},{......}]

提前致谢。

【问题讨论】:

  • 在 Object 中,值被写为 name : value 对。我没有得到您预期结果背后的逻辑。

标签: node.js mongodb


【解决方案1】:

在 Object 中,值被写为 name : value 对。 例如:

{
name : "M-DIT KOZHIKODE",
location : "Kerala",
established : 2012
}

我没有理解您预期结果背后的逻辑。

【讨论】:

    猜你喜欢
    • 2020-07-04
    • 2014-12-04
    • 1970-01-01
    • 2021-11-09
    • 2016-06-12
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多