I have a large document (~20KB) and through an AWS lambda i modify it. Almost all fields are updated during that process and through an http Request i want to replace the document with the new object that the lambda sends.
The process below achieves that, i was just wondering whether there’s another (better) way to do that since it feels weird to delete the _id field from my object (otherwise i get the error of trying to modify the _id field which is immutable) in order to replace it.
I will appreciate any advice. Thanks in advance!
const reqBody = body.text();
const jsonRequest = JSON.parse(reqBody);
var myObj = jsonRequest.myObj;
myObj.updatedAt = new Date().getTime();
let id = myObj._id;
delete myObj._id;
const options = { "upsert": false };
response.myObj= await context.services.get("myInstance")
.db("myDB")
.collection("myCollection")
.replaceOne({"_id": BSON.ObjectId(id) }, myObj, options);