i am trying to migrate from relational database (mysql) data to nosql (mongoDb) . But how can i ensure data integrity in mongodb . what i have found that we cannot do it on server side. what should i use on application side to handle data integrity ?
For eg: i have two tables user and task . Both have userId field common . if i add a new entry in task table it should check if userid present in user table. this is one of the requirement others like adding constraints , updating values etc
When you search for referential integrity in relation to Mongo-DB the standard response is "MongoDB does not support this". The standard explanation is that MongoDB supports refs and populate, however there is nothing that prevents you changing the ref to an invalid value.
Error checking and validation, for example, are common methods for ensuring data integrity as part of a process.
Ultimately, you're screwed. There's no way (in mongodb) to guarantee data integrity in such scenario, since it's lacking relations in general and foreign keys in particular. And there's little point in building application-level checks. No matter how elaborate they are, they can still fail (hence "no guarantee").
So it's either embedding (so that related data is always there, right in the document) or abandoning the hope of consistent data.
Steps to ensure Data Integrity:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With