how to update data subdocument array in mongoose

Solutions on MaxInterview for how to update data subdocument array in mongoose by the best coders in the world

showing results for - "how to update data subdocument array in mongoose"
Alessandro
06 Jan 2019
1// mongodb operation
2db.getCollection('profilesservices').update({
3  _id: ObjectId("6037ad8ac8f713f1d31abe38"), 
4 "workExperience._id": ObjectId("6037ad8ac8f713f1d31abe39")}, 
5   { $set: { "workExperience.$.companyName": "bukalapak" }
6   
7})
8
9
10//sample data
11}
12    "profileId" : "Sa4Dq9Xuw",
13    "photo" : "https://res.cloudinary.com/coding-street-art/image/upload/v1614261651/yxnvpazindsvz6lfst3m.jpg",
14    "gender" : "pria",
15    "birthDate" : ISODate("1997-03-19T17:00:00.000Z"),
16    "status" : "mahasiswa",
17    "nationality" : "indonesia",
18    "aboutMe" : null,
19    "resume" : "https://res.cloudinary.com/coding-street-art/raw/upload/v1614261653/bemkbknvhzknxffmala2.doc",
20    "skills" : [ 
21        "javascript", 
22        "typescript", 
23        "react", 
24        "vuejs", 
25        "express.js", 
26        "nodejs"
27    ],
28    "userId" : "602e8f43c0e227e6cb80bc56",
29    "workExperience" : [ 
30        {
31            "companyName" : "bukalapak", //before valie is bukopin
32            "jobPosition" : "data entry",
33            "startDate" : ISODate("2015-02-14T17:00:00.000Z"),
34            "endDate" : ISODate("2017-07-27T17:00:00.000Z"),
35            "workInformation" : "",
36            "_id" : ObjectId("6037ad8ac8f713f1d31abe39")
37        }, 
38        {
39            "companyName" : "procar international finance",
40            "jobPosition" : "general affair",
41            "startDate" : ISODate("2015-02-14T17:00:00.000Z"),
42            "endDate" : ISODate("2017-07-27T17:00:00.000Z"),
43            "workInformation" : "",
44            "_id" : ObjectId("507f1f77bcf86cd799439011")
45        }
46    ],
47    "education" : [ 
48        {
49            "institutionName" : "unindra",
50            "educationDegree" : "sarjana",
51            "fieldStudy" : "tehnik informatika",
52            "startDate" : ISODate("2015-03-24T17:00:00.000Z"),
53            "endDate" : ISODate("2020-03-24T17:00:00.000Z"),
54            "educationInformation" : "",
55            "_id" : ObjectId("6037ad8ac8f713f1d31abe3a")
56        }
57    ],
58    "appreciation" : [],
59    "volunteerExperience" : [],
60    "__v" : 0
61}