I have following structure of my mongodb I want to update medicine the how is I'm new in mongodb.
I can able to add and delete in medicine but how to update medicine.
"visitInfo": {
"conditions": [
"Musculoskeletal Pain"
],
"visitDate": "2019-10-07T13:59:00.000Z",
"cpInfo": "Dr. Rustom",
"isDummyUser": false,
"loginType": "client",
"createdAt": "2019-09-20T12:37:47.542Z",
"updatedAt": "2019-10-21T06:17:22.717Z",
"id": "5d84c81b9451de4de00cfaca"
}
},
"medicine": [
{
"doseTime": {
"doseTimes": [
{
"_id": "5dad86a0bfc4c07a1ee2334f",
"medicineTakenTime": "",
"time": "9:00 AM",
"quantity": "Take 1"
}
],
"doseTypes": "daily (no abbreviation)"
},
"schedule": {
"duration": "365 Days",
"startDate": "2019-10-21T00:00:00.000Z"
},
"_id": "5dad86a0bfc4c07a1ee2334e",
"medicineName": "TRIBENZOR (Oral Pill)",
"medicineIcon": "Circle",
"strength": " 5-12.5-20 mg Tab",
"instruction": "After eating"
},
{
"doseTime": {
"doseTimes": [
{
"_id": "5dad86a0bfc4c07a1ee2334f",
"medicineTakenTime": "",
"time": "9:00 AM",
"quantity": "Take 1"
}
],
"doseTypes": "daily (no abbreviation)"
},
"schedule": {
"duration": "365 Days",
"startDate": "2019-10-21T00:00:00.000Z"
},
"_id": "5dad86a0bfc4c07a1ee2334e",
"medicineName": "TRIBENZOR (Oral Pill)",
"medicineIcon": "Circle",
"strength": " 5-12.5-20 mg Tab",
"instruction": "After eating"
},
{
"doseTime": {
"doseTimes": [
{
"_id": "5dad86a0bfc4c07a1ee2334f",
"medicineTakenTime": "",
"time": "9:00 AM",
"quantity": "Take 1"
}
],
"doseTypes": "daily (no abbreviation)"
},
"schedule": {
"duration": "365 Days",
"startDate": "2019-10-21T00:00:00.000Z"
},
"_id": "5dad86a0bfc4c07a1ee2334e",
"medicineName": "TRIBENZOR (Oral Pill)",
"medicineIcon": "Circle",
"strength": " 5-12.5-20 mg Tab",
"instruction": "After eating"
}
]
Code:
db.getCollection("visits").update({ _id:ObjectId('5d9b1d859a1a4835a4c438ee'),"medicine._id": ObjectId("5d9b1d859a1a4835a4c438f1") },
{ $set: {
"medicine.$.medicineName": "TRIBENZOR (Oral Pill) updated dfgdfg 1",
"medicine.$.insttruction": "mid night 2",
"medicine.$.medicineIcon": "midhyperbola 3",
"medicine.$.strength": "midhyperbola 4",
"medicine.$.schedule.duration": "4 Days",
}
})
I want to update the medicine in all field