A
A
Alecxandrys2015-11-09 16:35:53
MongoDB
Alecxandrys, 2015-11-09 16:35:53

Why is the document not being published from the collection?

Good afternoon.
When a collection is published, it is not passed to the client.
Publishing occurs in the following way

Meteor.publish('battles', function ()
{
    var x=this.user().username;
    return battles.find({ $or: [ { name1: x}, { name2: x} ] },{fields:{name1:1,name2:1,battleID:1}})
});

At the same request, the correct document is displayed in the database console. When the code is executed on the site or when requested through the browser console, undef is returned without a document.
The user is logged in, there are documents in the collection that satisfy the condition by name for this user.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alecxandrys, 2015-11-10
@Alecxandrys

Unfinished address to the field is all to blame

Meteor.publish('battles', function ()
{
    var x = Meteor.users.findOne({_id: this.userId});
    return battles.find({ $or: [ { name1: x.username}, { name2: x.username} ] },{fields:{name1:1,name2:1,battleID:1}});
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question