python - How to make a field immutable after creation in MongoDB? -
use case: i'm writing backend using mongodb (and flask). @ moment not using orm mongoose/mongothon. i'd store _id of user created each document in document. i'd impossible modify field after creation. backend allows arbitrary updates using (essentially) collection.update_one({"_id": oid}, {"$set": request.json})
i filter out _creator_id field request.json (something del request.json["_creator_id"]
) i'm concerned doesn't cover possible ways in syntax modified cause field updated (hmm, dot notation?). ideally i'd way make fields write-once in mongodb itself, failing that, bulletproof way prevent updates of field in code.
imho there no know methods prevent updates inside mongo. can control app behavior, still able make update outside app. mongo don't have triggers - in sql world have possibility play data guards , prevent field changes.
as re not using odm, can have cqrs pattern allow control app behavior , prevent such updates.