Meteor.Collections: what is different from the new collection (null) and the new collection ({connection: null})

In Meteor.js, if I put the code on both the client and the server as:

var col = new Collection(null); 

What's the difference between:

 var col = new Collection('someName',{connection:null}); 

From the documentation:

new Meteor.Collection (name, [options])

name String: the name of the collection. If null, an unmanaged (unsynchronized) local collection is created.

connection Object A connection to the server that will manage this collection. Uses the default connection if not specified. Pass the return value of the DDP call. Connect to specify a different server. Pass null to indicate no connection.

From what he says, it looks like the above code is the same: both have two unconnected collections on the client and server. But why do you need to have two different ways to get the same result. My opinion is that the name does not matter, since they are not connected (there is no need to send DDP messages that must indicate the name of the collection). Am I missing something? Thanks.

+7
meteor
source share
1 answer

I understand that new Meteor.Collection( null ) is for a local collection that you do not want to publish. You can still publish it, but you will have to use the "added", "deleted" and "modified" publishing functions to indicate which collection on the client receives the data. The client will need to create a named collection to receive the data, but all db methods, such as “delete” or “update”, will be erroneous because they do not exist on the server.

On the server, new Meteor.Collection( 'someName', {connection: null} ) also exists only in memory, but can be used in the publish function in the same way as the collection supported by db. A client collection that receives data is created using new Meteor.Collection( 'someName' ) as usual, and the client will not be able to find out that this collection is only in the server’s memory .

On the client, I think that 'null'-named and' null'-connection are both ways to receive collections that cannot receive / send data from / to the server.

Some discussion here .


update: Collections on the server with {connection: null} do not receive methods configured for client access. These methods can be configured by temporarily creating a connection to collect and define methods. As below:

 //server js var serverOnly = new Meteor.Collection( 'serverOnly', {connection: null} ); serverOnly._connection = Meteor.server; serverOnly._defineMutationMethods(); serverOnly._connection = null; 

You still need to use allow / deny rules for the collection to allow client methods to work. If you find that you are using this hack, you should comment on the pull request, which makes these methods available by default .

+6
source share

All Articles