MongoDB data modelling: any drawbacks in using lots of databases?

瘦欲@ 提交于 2019-12-07 17:27:01

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/15221236/mongodb-data-modelling-any-drawbacks-in-using-lots-of-databases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!