I have one mongodb object like below :
{
"_id" : ObjectId("5e54934b2dfddc1826223bbb"),
"sellProducts" : {
"products" : []
},
"sellServices" : {
"services" : []
},
"categories" : [],
"status" : "Published",
"tags" : [],
"dateRange" : [],
"membershipRequired" : false,
"usersAttending" : [],
"cities" : [],
"companies" : [
ObjectId("5db1c84ec10c45224c4b95fd"),
],
"companyId" : ObjectId("5db1c84ec10c45224c4b95fd"),
"jobProfile" : [
ObjectId("5e549339a3ad20c97b7b0c7d")
],
"fundingBy" : []
}
Now I want to update the same record by pushing the value of the companyId field into the array of companies. How can I do that?
I tried below query but It didn't work :
db.getCollection('posts').update({_id: ObjectId("5e54934b2dfddc1826223bbb")},
{
$push:
{
companies: "$$companyId"
}
})