问题描述
最近我转移到MongoDB Web应用程序的后端部分,Web应用程序本身就是一个验证工具,工作流程如下所示:- 用户上传文件(通常是数十万行)
- 验证器检查它输出大量消息(可能每行多于一行) li>
- ...最后提供一些统计资料
我建模了我的应用程序,它自己的数据库包含:
- 该文件(通过GridFS保存)
- 包含消息的集合(在某些情况下可能超过一百万行)
- 具有统计资料的集合
我们有几百个用户,所以 MongoDB最终会有几百个DB 。
当然我可以拥有所有的数据在同一个数据库中,使用命名空间分隔来自不同用户的数据。然而,我觉得在连接URI中发送DB很方便,我发现更直观地发出一个drop database语句来清除用户,而不是在大型数据库中搜索和删除其数据。
我对MongoDB很新,所以我的问题是:在同一个MongoDB实例中有几个DB有什么缺点吗?或者有什么特别的考虑,我应该给这个问题?
我不熟悉MongoDB特别。通常,打开与数据库的连接是一个相对较慢的操作并绑定系统资源。这是否足以在您的情况下重要,我不能说。
为每个用户使用不同的数据库将使得难以执行访问多个用户的数据的查询。也许你不需要这样做。
尽管如此,我认为在每个记录中放置用户ID而不是创建一个简单的一般一个单独的数据库。单独数据库的收益是多少?好的,删除用户意思是说drop database。但是从单个数据库中删除用户应该意味着从tableX中删除user =?;从tableY中删除user =?等等,然而你有许多相关的表。我不能想象它是数百,对吧?也许有六十行代码呢?
I have recently moved to MongoDB part of the back-end of a web app, the web app itself is a validation tool, and the workflow looks like:
- the user uploads a file (typically hundreds of thousands of lines)
- the validator checks it outputting a lot of messages (possibly more than one per line)
- ...and finally provide a few statistics
I modelled my application so that each user has it's own DB containing:
- The file (saved through GridFS)
- A collection containing the messages (possibly over a million lines, in some cases)
- A collection with the statistics
We have a few hundreds of users, so MongoDB will end up having a few hundreds DBs.
Of course I could have hold all the data in the same DB, using namespaces to separate data from different users. However I felt it was handy to send the DB in the connection URI, and I found more intuitive to issue a "drop database" statement to purge a user, rather than searching and removing its data in the large DB.
I am pretty new to MongoDB, so my question is: is there any drawback in having several DBs in the same MongoDB instance? Or is there any special consideration that I should give to the problem?
I'm not familiar with MongoDB specifically. In general, openning a connection to a database is a relatively slow operation and ties up system resources. Whether this is enough to matter in your case I can't say.
Having a different db for each user would make it difficult to perform queries that access data for multiple users. Maybe you have no need to do this.
Still, I would think it would be a whole lot simpler in general to just put a user id in each record rather than create a separate database. What's the gain of separate databases? Okay, deleting a user means saying "drop database". But deleting a user from a single database should mean saying "delete from tableX where user=?; delete from tableY where user=?" etc for however many relevant tables you have. I can't imagine it's hundreds, right? Maybe half a dozen lines of code or so?
这篇关于MongoDB数据建模:使用大量数据库的任何缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!