2014-10-19 1 views
0

작동하는 유성 리더 보드 예제를 기반으로하는 테스트 앱이 있지만 내 앱을 만들 때 데이터를 표시 할 수없고 쿼리가 작동하지 않습니다. 유령 문고를 터미널 창에서 실행하면 삽입되는 데이터가 있음을 알 수 있습니다.유성 mongodb 앱에 데이터를 표시 할 수 없습니다.

db.games.find(); 

은 모든 게임을 표시합니다.

db.games.remove(); 

은 모든 게임을 삭제하지만 내 유성 앱에서는 작동하지 않습니다.

삽입물을 제외하고이 앱의 어떤 것도 작동하지 않습니다.

if (Games.find().count() === 0) 

은 항상 0을 반환합니다.

여기 내 main.js 파일입니다.

var court = 1; 

var currentDate = new Date; 

var gameDate = new Date("2014-10-19"); 

var gameTime = new Date("21:15"); 

var MinutesSinceMidnightNow = (new Date() - new Date().setHours(0,0,0,0))/6000; 

var MinutesSinceMidnightGameTime = (new Date().setHours(21,15,0,0) - new Date().setHours(0,0,0,0))/6000; 

Games = new Meteor.Collection("games"); 

if (Meteor.isClient) { 

    Template.game.helpers({ 
    games: function() { 

     return Games.find({}); 

    } // players func 
    }); //template helpers 

Meteor.startup(function() { 
    if (Games.find().count() === 0) { 
    Games.insert({ 
    "court_id": court, 
    "game_date": gameDate, 
    "court_name": 'Court 1', 
    "game_time" : gameTime, 
    "team_a": "bulldogs", 
    "team_b": "sea eagles", 
    "team_a_score": 0, 
    "team_b_score": 0, 
    "game_duration": 75, 
    "game_half": 0, 
    "game_quarter": 15, 
    "quarter_time": 3, 
    "half_time": 5, 
    "game_minutes": MinutesSinceMidnightGameTime 
    }); 
    } 
}); 

} // isClient 

if (Meteor.isServer) { 
    Meteor.startup(function() { 

    Games.remove(); 

    }); 
} 

여기 내 HTML 파일입니다. 당신이 경쟁 조건으로 실행중인

<head> 
    <meta name="viewport" content="width=device-width, user-scalable=no"> 
</head> 

<body> 
    <div class="outer"> 
    {{> scoresheet}} 
    </div> 
</body> 

<template name="scoresheet"> 
    <div class="scoresheet"> 
    {{#each games}} 
     {{> game}} 
    {{/each}} 
    </div> 
</template> 

<template name="game"> 
    <div class="game"> 
    <h1>"Hello"</h1> 
    <span class="name">{{game_time}}</span> 
    <span class="name">{{court_name}}</span> 
    <span class="name">{{team_a}}</span> 
    <span class="name">{{team_b}}</span> 
    <span class="score">{{team_a_score}}</span> 
    <span class="score">{{team_b_score}}</span> 
    </div> 
</template> 
+0

자동 게시 패키지를 제거 했습니까? 그렇다면 일부 데이터를 구독해야 클라이언트에서 볼 수 있습니다. – richsilv

+0

컬렉션을 비우려면 선택기'{}} - [docs # remove 참고] (http://docs.meteor.com/#remove)를 포함시켜야합니다. 그러면 Games.remove ({}))' – garrilla

+0

그냥 나에게 발생했다. 서버 시작시'.remove()'를 놓으면 경쟁 조건이 생기게된다. 적어도 서버를 정상적인 서버로 옮겨야하지만, 아래 답변 ... – garrilla

답변

0

...

컬렉션 Games 선언하지만 대답이 경우에도 0이됩니다 있도록 수집하기 전에 Games가 동기되는 후 Games.find()가 실행되는 쿼리 n> 0

앱이 완전히로드되면 콘솔에서 Games.find().count()을 실행하여 테스트 할 수 있습니다. n을 인쇄해야합니다.

해결책은, 당신이 컬렉션의 문서가있을 기대 할 때하는 것은 autorun

Meteor.autorun(function() { 
    if(Games.findOne()) { 

     //do your stuff here 
     } 

    }); 

에 포장하는 것입니다 그러나 이것은 여전히 ​​N = 0

의 사례와 실패

은 그래서 당신은 실제의에서, 그러나 DDP._allSubscriptionsReady()

timer = Meteor.setInterval(function(){test();}, 200); 

test = function(){ 
    if(DDP._allSubscriptionsReady()) action(timer); 
}; 

action = function(timer){ 
    Meteor.clearInterval(timer); 

    /* now do stuff */ 
    console.log('subs are ready, really ready', Games.find().count()) 
}; 

에 대한 타이머 및 테스트에 넣어 수 당신은 autopublish 패키지를 제거하고 발행/가입을 설정하고 구독 콜백에 코드를 넣는 것을 고려해야합니다. this answer

+0

자동 실행은 아무런 차이가 없습니다. 콘솔에는 정확한 수의 게임이보고되지만 DB에있는 게임의 수와 관계없이 앱이 삽입됩니다. – markhorrocks

+0

레코드가로드되어 있는지 테스트하고, 그렇지 않은 레코드를 새로 받으려면 클라이언트가 필요합니다. 가급적이면 일부 레코드를 지우고 클라이언트 시작시 APi에서 새로 고치고 싶습니다. – markhorrocks

+0

@markhorrocks [이 데모] (http : //fvrs.meteor.co.kr /) - 브라우저 콘솔에서 코드를 노출 할 수는 있지만 ... .remove ({}) 메소드를 사용하여 서버의 콜렉션을 비우는 것을 볼 수는 없습니다. – garrilla

관련 문제