且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Meteor,动态定义集合

更新时间:2023-02-14 09:54:36

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



您可能希望查看 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.