First I will give you a simple output:
{
"_id" : ObjectId("6016fcca3a406de622cfdc8f"),
"pfname" : "charbel",
"plname" : "alam",
"address" : "Baskinta",
"gender" : "Male",
"phone" : "",
"age" : "22",
"addmissions" : [
{
"sickness" : "diabete",
"arrival_date" : "13-1-2021",
"payments" : [ ]
}
],
"consultations" : [ ]
}
I am new to MongoDB and I want to add a document inside the array "payments" which is inside the "addmissions" array
I have been trying this command:
db.patients.update( {"pfname":"charbel"}, {$set:{"addmissions": {"sickness":"diabete","arrival_date":"13-1-2021", {$push:{"payments":{"medicaments":[],"surgeries":[],"total_price":"100000","amount_paid":"60000","amount_left":"40000"}}} }} });
But I am getting the following error: uncaught exception: SyntaxError: expected property name, got '{' :
I also tried something like this:
db.patients.update({"pfname"
:"charbel"},{$push:{addmissions.payments:{"medicaments":[],"surgeries":[],"total_price":"100000","amount_paid":"60000","amount_left":"40000"}}})
It is giving me this error: uncaught exception: SyntaxError: missing : after property id :
I also want to add a record to the medicaments array I am trying this query:
db.patients.update({
"pfname":"charbel",
"addmissions.sickness":"diabete",
"addmissions.arrival_date":"13-1-2021",
"addmissions.payments.total_price":"100000",
"addmissions.payments.amount_paid":"60000",
"addmissions.payments.amount_left":"40000"
},{$push:{"addmissions.$.payments.medicaments":{"medname":"panadol","medprice":"30000"}}})
But it is giving me this error:
"errms
g" : "Cannot create field 'medicaments' in element {payments: [ { medicaments: [], surgeries: [], total_price: "100000", amount_paid: "60000", amount_left: "40000" } ]}"