Hi @Kushagra_Kesav,
Here is an exported box document which has multipe relatedJobs:
[{
"_id": {
"$oid": "63da3c1feac7af351445caad"
},
< many more fields >
"relatedJobs": [
{
"partnerId": "41",
"completedAt": "2022-09-13",
"jobType": "RECEPTION_JOB",
"weight": 1972,
"jobId": "tCDcpp4K1JFfsXju6LYQ"
},
{
"jobId": "TDfrqods85bQYECOa3n3",
"partnerId": "13",
"jobType": "DELIVERY_JOB",
"completedAt": "2023-01-18",
"weight": 23060
}
]
}]
And this is the 2 jobs related to it:
[{
"_id": {
"$oid": "63da2b01eac7af351445c946"
},
"firebaseId": "TDfrqods85bQYECOa3n3",
"completedAt": "2023-01-18",
"createdAt": "2023-01-18",
"dueAt": "2023-01-18",
"partnerId": "13",
"startedAt": "2023-01-18",
"status": "DONE",
"jobType": "DELIVERY_JOB",
< many more fields >
},{
"_id": {
"$oid": "63da2b01eac7af351445ca57"
},
"firebaseId": "tCDcpp4K1JFfsXju6LYQ",
"completedAt": "2022-09-13",
"createdAt": "2022-09-13",
"dueAt": "2022-09-13",
"partnerId": "41",
"startedAt": "2022-09-13",
"status": "DONE",
"jobType": "RECEPTION_JOB",
< many more fields >
}]
Currently the jobId
in a relatedJobs
array element contains the firebaseId
from the job and that’s my only connection to it. I want to replace that obsolete reference with the job’s _id
which is the ObjectId while preserving everything else as it was. The updated box document should look similar to this:
[{
"_id": {
"$oid": "63da3c1feac7af351445caad"
},
< many more fields >
"relatedJobs": [
{
"partnerId": "41",
"completedAt": "2022-09-13",
"jobType": "RECEPTION_JOB",
"weight": 1972,
"jobId": {
"$oid": "63da2b01eac7af351445ca57"
}
},
{
"jobId": {
"$oid": "63da2b01eac7af351445c946"
},
"partnerId": "13",
"jobType": "DELIVERY_JOB",
"completedAt": "2023-01-18",
"weight": 23060
}
]
}]
My current approach is to write JavaScript for it where I already converted some strings to date:
const db = db.getSiblingDB("database_name");
const boxes = db.boxes;
const jobs = db.jobs;
boxes.updateMany( {}, [
{ $set: {
fillDate: { $dateFromString: { dateString: "$fillDate", format: "%Y-%m-%d" } },
expirationDate: { $dateFromString: { dateString: "$expirationDate", format: "%Y-%m-%d" } }
} }
] );
Please let me know if there is any more info I should provide.
Thanks