0

I'm looking for suggestions on how to debug this one.

When one of my documents gets too large in a collection, the entire document is removed from the collection. I'm using heroku with mongoid 2.2.6 and rails 3.0.20 with MongoHQ. I'm unable to reproduce the problem locally.

We started writing this code two years ago and it's been slowly maintained by some of my students. The site is similar to a basic blogging site where a "post" will have "comments." The initial design had the post versioned and each post contains all of the comments. Because of versioning, the size of the document can grow very quickly. We tried to limit the size of the versions with max_versions 5, but we can still reproduce the problem with extremely large comments. It may be the case that the site is fully useable, but since we loose the entire document (and not just the comment), I'd like to find a solution. Had I noticed that the comments were being versioned within the document, I'd have change the design to store comments outside of the post.

4

2 回答 2

0

一些可能有帮助的信息:

  • 如果文档超过 16MB 限制,服务器将不会删除该文档;相反,它会引发错误(例如,大小无效)。

  • 据我所知,如果更新操作失败,Mongoid 和 MongoDB Ruby 驱动程序都不会删除文档。

  • 如果应用程序删除一个文档,然后为每次更新插入一个新文档,我建议修改应用程序以利用更新并确保正确处理任何错误。

于 2013-02-07T23:35:59.647 回答
0

正如评论所说,您的文档很可能只是变得太大。一段时间以来,所有 MongoDB 驱动程序都默认为 Acknowledged Writes,如果无法存储或更新文档,在大多数情况下,这会给您一个异常。请检查您是否使用最新的驱动程序版本和/或是否打开了确认写入(有时也称为“安全”)。

我仍然认为你最好的选择是改变你的架构。如果您有大量的评论,那么即使在某些时候没有版本控制,您也会遇到这个问题。或者,您可以将较旧的评论和/或帖子存储在单独的集合中。

于 2013-02-07T23:27:20.197 回答