如何访问嵌套模式中的元素?

时间:2018-09-03 11:53:44

标签: node.js mongodb express mongoose postman

{
        "_id" : ObjectId("5b8d1ecbb745685c31ad8603"),  
        "name" : "abc",  
        "email" : "abc@gmail.com",  
        "projectDetails" : [   
        {  
            "technologies" : [  
                "abc",   
                "abc"  
            ],  
            "_id" : ObjectId("5b8d1ecbb745685c31ad8604"),  
            "projectName" : "abc",  
            "projectDescription" : "abc",  
            "manager" : "abc",  
            "mentor" : "abc"  
        }  
    ],  
    "__v" : 0  
}  

在这里,projectDetails是一个对象数组。我想更新projectDetails中的元素“ projectName”。如何在邮递员中为相同的请求编写PUT请求?

1 个答案:

答案 0 :(得分:0)

  

请尝试以下查询

db.users.update({ "email" : "abc@gmail.com","projectDetails._id":ObjectId("5b8d1ecbb745685c31ad8604")},{ $set: { "projectDetails.$.projectName" : "test" } })
  

您的网址应该是这样

http://localhost:3000/project/5b8d1ecbb745685c31ad8604
  

您的如下所述的看跌期权请求

router.route("/updateProject",function(req,res){
var id = req.query.project_id; // Check syntax for framework you are using 

});