简体   繁体   English

使用出版物还是分成收藏(演出)?

[英]Use publications or separate into collections (performance)?

I have a collection, in which only two queries are ever called on it. 我有一个集合,其中只调用了两个查询。

Ex. 例如 Cars.find({color: 'red'}); and Cars.find({color: 'blue'}); Cars.find({color: 'blue'});

I was wondering if I should just create RedCars and BlueCars collections instead of using two publications on Cars . 我想知道是否应该只创建RedCarsBlueCars集合,而不是使用有关Cars两个出版物。

Thinking of performance here, if the Cars collection were to get very large, would it be more performant to use two collections? 考虑到这里的性能,如果Cars系列变得很大,那么使用两个系列是否会更出色? Also, they are never called on the same template. 而且,它们永远不会在同一模板上调用。 Each has its own template. 每个都有自己的模板。

Thanks 谢谢

From a Mongo perspective, if you have a scenario where a single field across documents within a collection begins to look like an index (as you have described above) it will actually start to index queries against that field and make the return highly tuned. 从Mongo的角度来看,如果您遇到一个场景,即集合中文档中的单个字段开始看起来像索引(如上所述),则实际上它将开始针对该字段建立索引,并使返回值得到高度调整。 You can update this index (and if you have a lot of data that falls into scenario like you have described, you should tune this index), using standard Mongo indexing parameters against the database. 您可以使用针对数据库的标准Mongo索引参数来更新此索引(如果您有很多数据属于上述情况,则应调整此索引)。 There is more to this performance as well. 此性能还有更多。 For example, if it is a high read, low write, then Mongo will often keep portions or all of the query in memory for quick retrieval if it can. 例如,如果是高读,低写,则Mongo经常会将部分或全部查询保留在内存中,以便可以快速检索。

As for whether it is better to split these into two collections. 至于将它们分成两个集合是否更好。 That's a tough one. 这是一个艰难的过程。 From a performance standpoint it might be about the same either way if you tune your indexes properly and allow Mongo to do what it does best. 从性能的角度来看,如果您正确地调整索引并允许Mongo尽其所能,则这两种方法可能大致相同。 However, from the meteor standpoint, I would consider it much easier to just keep them in a single collection from a code maintainability and testability standpoint. 但是,从流星的角度来看,从代码可维护性和可测试性的角度来看,我认为将它们保存在单个集合中要容易得多。

In terms of performance, if the collection does get large, then your application will end up receiving alot more data than you expected it to if changes are made on either blue or red cars. 在性能方面,如果集合确实变大,那么如果对蓝色或红色汽车进行更改,则您的应用程序最终将收到比您期望的更多的数据。 A good solution rather than creating two collection is to use a parameterized subscription that will filter only on the data set you are looking at. 一个比创建两个集合更好的解决方案是使用参数化订阅,该订阅将仅根据您要查看的数据集进行过滤。

eg 例如

    Meteor.publish('cars', function(c) {
        check(c, String);
        return Cars.find({color: c});
    });

Then you can access the data by subscribing Meteor.subscribe('cars', 'blue') 然后,您可以通过订阅Meteor.subscribe('cars', 'blue')访问数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM