Please help.
I have a collection called ChatList which i have triple checked (before removing the autopublish package) that it has 5 documents in it. The autopublish package is now removed and with the following code, all it returns is an empty collection in the chrome console. That is, when ChatList.find().fetch() is entered, all that it shows is [ ].
What am i doing wrong? its driving me crazy.
mychatapp > server > server.js
if(Meteor.isServer){
Meteor.publish(‘chatsLists’,function(){
var currentUser = this.userId;
return ChatList.find({createdBy: currentUser});
});
Are you shure this.userId is defined (user is logged) and colllection has documents for current userid? Note that autopublish publishes all the collections without any filters.
Exactly what @rajivguliani has said. Are you sure there are any documents in the collection?
The other thing i was going to suggest was maybe you haven’t defined the collection properly.
However from that console screenshot it looks fine because its got all the right attributes.
Since you are using this.userId to filter out the appropriate chats from your collection, I assume you use the accounts system.
Have you tried wrapping the subscribe into Tracker.autorun so it gets refreshed when the user actually logs in? You could also add a console.log(this.userId) to your publish function to see what your server is actually querying the collection for.
Tracker.autorun(function(){
var userId = Meteor.userId();
Meteor.subscribe('chatList');
});
Thank you everyone for all the help. This community is great.
I came home from work yesterday and it randomly started working properly without changing anything. not sure what happened