我可以使用 MongoDB 来实现这个设计吗(通过 pyMongo)

Will I be able to implement this design using MongoDB (via pyMongo)

这会有点冗长post,提前致歉。我有一些使用 MongoDB 的经验(有一段时间了),我对 python 也一般,但我有一个大项目,我希望在花大量时间编码之前得到一些反馈。

该项目涉及创建一个画廊,可以在其中选择单个演示幻灯片(来自 apple keynote '09)并将其一起解析为演示文稿。这样,拥有几千张幻灯片的用户可以使用该程序通过混合和匹配旧幻灯片来创建新的演示文稿,而不必打开每个演示文稿并将所有需要的幻灯片手动复制粘贴到新的演示文稿中。

程序中有一个包含所有幻灯片的主图库。每张幻灯片都可以选择并分配可搜索的标签。可能会形成新的 "groups" 幻灯片,其中所有带有特定标签集的幻灯片都会自动添加到组中。此外,可以将单个幻灯片从主图库中拖放到用户创建的组中。

每张幻灯片都有一个包含预览图像的文件夹,这就是我认为我需要 MongoDB 的原因:通过拥有一个数据库,其中每张幻灯片都是一个文档,其中包含幻灯片的文件名、幻灯片的预览缩略图,以及包含可搜索标签词的数组,将能够非常快速地查询特定的幻灯片集。该查询将 return 一组匹配的幻灯片,然后可以循环访问这些幻灯片以将每张幻灯片缩略图添加到 GUI 画廊。用户创建的"groups"可以是单独的集合,其中创建组时创建集合,幻灯片根据需要从集合中added/removed,删除组时可以销毁集合。这也将允许永久存储,因为数据库及其集合将在打开和关闭程序之间持续存在。

我的问题是,我能否使用 MongoDB(通过 pyMongo)以良好的性能执行以下操作:

-根据需要创建和删除集合 - 将特定文档从主集合复制并删除到新创建的集合中 - 在与每个文档关联的动态数组中以字符串格式存储一组可搜索标签 - 根据存储在每个文档中的数组中的单个标记词查询集合中的幻灯片 - 在系统关闭和打开/关闭程序之间维护数据库。

谢谢!

下面引用了您post的观点和问题。我的评论跟在每个引用之后。


By having a database where each slide is a document that contains the filename of the slide, the filename of the preview thumbnail of the slide, and an array containing searchable tag words, one will be able to query specific sets of slides very quickly.

听起来不错。我假设幻灯片在一张 collection.

The user-created "groups" can be individual collections, where a collection is created when a group is created, slides are added/removed from the collection as needed, and the collection can be destroyed when the group is deleted.

我建议您不要为每个组创建一个collection。您最终可能会用成百上千个 collection 来表示 "groups"。如果您决定要引入分片(这可能只能在 collection 上完成),这可能会让您陷入困境。考虑为 "groups" 创建一个 collection,它将包含与组关联的唯一用户 ID。

[Will I be able to use MongoDB, with decent performance, to] create and delete collections as needed?

不断地创建和删除 collections 不是好的设计。您可能不需要这样做。如果您熟悉 RDBMS,那么 collection 类似于 table。您会继续即时创建 dozens/hundreds/thousands 个 table 吗?可能不是。

[Will I be able to use MongoDB, with decent performance, to] copy and delete specific documents from a master collection into newly created collections?

是的,可以从一个 collection 获取数据并将其保存到另一个 collection。删除文档也非常简单且高效。 (索引是你的朋友。)

[Will I be able to use MongoDB, with decent performance, to] store an array of searchable tags in string format in a dynamic array associated with each document?

是的。 MongoDB 非常擅长这个。

[Will I be able to use MongoDB, with decent performance, to] query slides within a collection based on a single tag word stored in an array within each document?

是的。体面的性能将取决于您的 collection 的大小,更重要的是,相关索引的存在。

[Will I be able to use MongoDB, with decent performance, to] maintain the database between system shutdowns and opening / closing the program?

我假设您指的是复制和故障转移。如果是这样,是的,MongoDB 很好地支持这一点。