I have created a mongodb collection in python django.The collection name is audit_details and it consists of following data
_id:630e026211cb34947c85a7a5
user:"akhil"
status:null
old_data:null
new_data:2022-08-30T17:58:18.551+00:00
_id:630e026211cb34947c85a7a6
user:"sandeep"
status:null
old_data:null
new_data:2022-08-30T17:58:18.551+00:00
now,i want the new_data value to be assigned to “old_data” and the “new_data” will take the “updated_time” value taken from API post request(I am using django restframework and the data i am sending as post request is {“action”:“modify”,“user”:"sandeep,“updated_time”:“2022-08-26 16:26:00”})
i want the output to be like below
_id:630e026211cb34947c85a7a6
user:"sandeep"
status:modified
old_data:migration was scheduled at 2022-08-30T17:58:18.551+00:00
new_data:migration now scheduled at "2022-08-26 16:26:00"
I have tried the following:
audit_details.update_many({ "user": "sandeep" },
{
"$currentDate": {
"last_modified": True,
},
"$set": {
"status": "modified",
"old_data": {"$concat":["Migration Task was scheduled at ", "$new_data"]},
"new_data" : {"$concat": ["Migration Task now scheduled at ", request.data['updated_time']]}
}
}
)
my output is like below,which is not correct:
{
"_id": {
"$oid": "630e026211cb34947c85a7a5"
},
"user": "sandeep",
"status": "modified",
"old_data": {
"$concat": [
"Migration Task for",
"$new_data"
]
},
"new_data": {
"$concat": [
"Migration Task for",
"2022-08-26 16:26:00"
]
},
"last_modified": {
"$date": {
"$numberLong": "1661917054163"
}
}
}