stylesuxx
stylesuxx

Reputation: 845

Meteor collection differs on server and client

I have a collection called GameMaps, defined like this:

GameMaps = new Meteor.Collection('gameMaps');

An entry in this collection looks like this:

{
  name: 'foo',
  structure: {
    arg1: 'bar',
    fields: [
      {name: 'someName', value: 'someValue'},
      {name: 'someOtherName', value: 'someOtherValue'}
    ]
  }
}

Now on the server I can access the first field of the structure in the following way:

GameMaps.findOne({name: 'foo'}).structure.fields[0]

which returns this object as expected:

{name: 'someName', value: 'someValue'}

But when I try to execute the same on the client I get an empty object:

Object {}

My publication for the collection looks like this:

Meteor.publish('allMaps', function() {
  return GameMaps.find();
});

And the subscription like this:

Meteor.subscribe('allMaps');

On the client I see everything of this collections item except for the objects in the "fields" array. I even see the amount of items in the "fields" Array but can not access them. I guess I am missing something when publishing the collection, but I don't see what.

Upvotes: 2

Views: 136

Answers (1)

Mike Graf
Mike Graf

Reputation: 5307

As you identified in your comments, your issue is that you have a field named "length" . Unfortunately the serialisation code mistakes the object as an array if it has a length property.

See bug report.

A hacky workaround is to rename the field to something else like safeLength, overrideLength, len or even langth .

Upvotes: 2

Related Questions