我们如何确保mongoDb中的数据完整性? [英] How can we ensure Data integrity in mongoDb?

查看:380
本文介绍了我们如何确保mongoDb中的数据完整性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从关系数据库(mysql)数据迁移到nosql(mongoDb).但是我如何确保mongodb中的数据完整性.我发现我们无法在服务器端做到这一点.我应该在应用程序端使用什么来处理数据完整性?

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 ?

例如:我有两个表user和task.两者都有userId字段common.如果我在任务表中添加新条目,则应检查用户表中是否存在用户标识. 这是其他要求之一,例如添加约束,更新值等

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

推荐答案

最终,您被搞砸了.在这种情况下,没有办法(在mongodb中)来保证数据的完整性,因为它缺乏通用键和外键之间的关系.而且,构建应用程序级检查毫无意义.无论它们多么复杂,它们仍然会失败(因此不能保证").

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.

这篇关于我们如何确保mongoDb中的数据完整性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆