Meteor: How can I tell when the database is ready?

后端 未结 6 914
醉话见心
醉话见心 2020-12-01 11:39

I want to perform a Meteor collection query as soon as possible after page-load. The first thing I tried was something like this:

Games = new Meteor.Collecti         


        
6条回答
  •  有刺的猬
    2020-12-01 11:54

    Here is another tidbit of information for those who may be using userid or some part of user info stored in Meteor.users database. When the page first loads the Meteor subscribe, going on in the background, may not be complete itself. Therefor when you try to connect to another database to query for that, it will not pull the information. This is because the Meteor.user() is still null itself;

    The reason, like said above, is because the actual Meteor users collection has not gotten through pulling the data.

    Simple way to deal with this.

    Meteor.status().connected

    This will return true or false, to let you know when the Meteor.user collection is ready. Then you can go on about your business.

    I hope this helps someone, I was about to pull my hair out trying to figure out how to check the status. That was after figuring out the Meteor user collection itself was not loaded yet.

提交回复
热议问题