当我从 /data/db 中删除所有文件时,为什么会保存 MongoDB 数据?
我刚刚开始在 Rails 3 中使用 MonogDB。在做了一些基准测试之后,我发现它的执行速度比 Postgresql/pg 快 5-10 倍。
我决定检查数据的存储方式,因此我从 /data/db 中删除了所有文件(该文件夹包含“mydb.0”、“mydb.1”等文件。
但是我仍然可以从 Rails 应用程序访问数据即使在重新加载服务器之后,
是否有任何类型的临时或缓存文件夹包含所有包含数据的 .json 文件?
I just started using MonogDB with Rails 3. After doing some benchmarks, I found out that it performs 5-10 times faster than Postgresql/pg.
I decided to check how the data is stored, so I removed all the files from /data/db (that folder contained files like "mydb.0", "mydb.1" etc.
However I still can access data from my Rails app! Even after reloading the server.
So is there any kind of temp or cache folder with all the .json files with data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确答案是这是 UNIX 功能,而不是 mongo。 (我假设你使用的是 Linux)
Mongo 使用内存映射文件作为存储。除其他外,这意味着 mongo 很可能始终保持所有文件打开。
在 Unix 上,一旦使用文件的最后一个进程关闭文件,文件就会被删除,而不是在您发出“rm”命令时。
在这种情况下,rm 命令取消文件链接(从目录中删除条目,因此无法再次访问)。
所以,答案是,一旦停止 mongo,该文件就会被操作系统删除。
请注意,该文件仍在使用磁盘空间,即使“df”或“du”表示不是。这可能会令人困惑,因为您可能会出现“磁盘已满”错误,并在“df”上报告大量可用空间。
您可以删除此文件,但是:
The correct answer is that this is a UNIX feature, not mongo. (I presume you are using Linux)
Mongo uses memory mapped files as a store. Among other things this means that most probably mongo keeps all the files open all the time.
On Unix, the files are removed as soon as the last process using the files closes them, not when you issue the "rm" command.
In this case, the rm command unlinks the file (Removes the entry from the directories, so cannot be accessed again).
So, the answer is that the file will be removed by the OS as soon as you stop mongo.
Note that the file is still using disk space, even if "df" or "du" says is not. This can be confusing as you can have "disk full" errors with lots of free space reported on "df".
You can delete this files but: