I am trying to sync my server collection with my client collection.
On the Server:
var JobLoopUsers = new Meteor.Collection("job-loop-users")
Meteor.publish("user-data", function(){
JobLoopUsers.findOne({meteorUserId : 1});
});
On the Client:
Meteor.subscribe("user-data");
JobLoopUsers = new Meteor.Collection("job-loop-users");
I insert some test data on the server using meteor.call
On the server when I do
console.log( JobLoopUsers.find().fetch()[0] )
it displays:
{meteorUserId: 1
testData: "My Test Data Here"}
When I do
console.log( JobLoopUsers.find().fetch())
on the client I just get an empty array.
How do I sync up these two collections?
The Meteor Docs say :
When you subscribe to a record set, it tells the server to send records to the client. The client stores these records in local Minimongo collections, with the same name as the collection argument to set. Meteor will queue incoming attributes until you declare the Meteor.Collection on the client with the matching collection name.
Do I need to do an autosubscribe?
These two are automatically sync’d in realtime. What might be happening is the data you are inserting doesn’t have a
meteorUserId:1and it is not published to the client, and you’re searching for all records whether they havemeteorUserId:1or not.To fix this try and alter:
You don’t have to do an autosubscribe unless you need a subscription to change for some reason
You may also be calling
console.log( JobLoopUsers.find().fetch())too soon, try waiting a second or two, replace it with: