Retrieving Data from Meteor Collections

前端 未结 5 1400
北恋
北恋 2021-02-08 18:54

I\'m having a few problems when trying to get data from a Meteor Collection and I need some advice.

The collection has been defined, published, and subscribed successful

5条回答
  •  故里飘歌
    2021-02-08 19:20

    I recently had the same problem, The collection find() returned nothing when used from a query.observe.

    The problem was the order of the subscribe of collections.

    For example if you have a collection called Lists and one called Projects,

    If you're getting the projects by observing a query on lists, and you had :

    Meteor.subscribe('Lists');
    Meteor.subscribe('Projects');  
    

    What happens is the query observe trigger is called, but the Projects are not yet fetched from the server. So Projects.find().fetch().length = 0.

    To fix it, simply do

    Meteor.subscribe('Projects');    
    Meteor.subscribe('Lists');
    

提交回复
热议问题