Meteor,动态定义集合 [英] Meteor, define collections dynamically

查看:95
本文介绍了Meteor,动态定义集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个应用程序,需要能够即时创建新的Mongo集合。目前我们有这样的代码:

  @Global = new Meteor.Collection('global')

我们在这个mongo集合中有一个文档,如下所示:

  {title:room_list,room_list:['chat1','chat2'],...} 
pre>

现在我想设置一些类型的循环或构造,基本上创建以下



  @ chat1 = new Meteor.Collection('chat1')
@ chat2 = new Meteor.Collection('chat2')

我们似乎需要这种类型的功能,以便能够即时创建新的数据集合。



我们正在研究某种类型的动态变量声明,或者是否有更好的方法来动态创建新的流星集合?

解决方案

在大多数情况下,您可能不想创建多个集合,而是使用一个集合,并根据其订阅将视图发送给客户端。



您可能希望查看 https://github.com/mizzao/meteor-partitioner 包它是专为此目的而设计的,并且包括如何对于多个聊天室这样做的示例。您还可以查看 https://github.com/mizzao/CrowdMapper 查看实施示例。


We are working on an app and need to be able to create new Mongo collections on the fly. Currently we have code such as this:

@Global = new Meteor.Collection('global')

We have a document in this mongo collections that looks like this:

{ "title" : "room_list", "room_list" : ['chat1', 'chat2'], ... }

Now I want to set up some type of loop or construct that would basically create the following

@chat1 = new Meteor.Collection('chat1')
@chat2 = new Meteor.Collection('chat2')

We are seeming to need this type of functionality to be able to create new collections of data on the fly.

We are looking into some type of dynamic variable declaration or is there a better way to dynamically create new meteor collections?

解决方案

In most instances, you probably don't want to create multiple collections, but instead use one collection and send views of it to clients depending on their subscription.

You may want to check out the https://github.com/mizzao/meteor-partitioner package I've built which is designed especially for this purpose, and includes an example for how to do this for multiple chat rooms. You can also see https://github.com/mizzao/CrowdMapper for an implemented example.

这篇关于Meteor,动态定义集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆