I’m interested in migrating from a relational DB to MongoDB for the performance improvements. I would be storing redundant, denormalized data in multiple locations and am wondering if it is possible to automatically maintain the integrity of data WITHOUT application code.
For example, if I have a User document…
User: { _id: "...", userName: "johndoe", displayName: "John Doe", TotalTasks: 3 }
And then a Task document…
Task: { _id "...", title: "Finish Reports", userID: "...", userName: "johndoe", userDiplayName: "John Doe" }
How can I automatically ensure that userName and displayName stay the same in the appropriate documents? How can I ensure that TotalTasks is updated when new tasks are added or deleted for this user?
You can’t enforce these constraints on the server side. However triggers are something that’s planned. The only constraint that’s currently supported is unique indexes.