Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Note: the initial answer and the bug reproduction that followed it are completely different. The one helped to spot another. Looks for the second part of this answer for real information.</p> <p><strong>Answer to the initial question:</strong></p> <p>This behavior makes sense to me:</p> <p>Let's look at your query:</p> <pre><code>Games.find({date: {$gte: new Date()}}, {sort: {date: 1}}) </code></pre> <p>You are looking for all games, sorted by date whose date is <strong>greater than</strong> the date the <strong>query</strong> is <strong>created</strong>.</p> <p>So let's say you have following items in the database:</p> <pre><code>A, date: 100 B, date: 200 C, date: 300 </code></pre> <p>Your client js is loaded and the current time is <code>350</code>. Your query is created as <code>Games.find({ date: {$gte: 350} }, {sort: {date: 1}});</code>. Surely A, B and C are behind <code>350</code> date and thus are not rendered.</p> <p>Then you insert a new game into database, say <code>D, date: 400</code>. Yes, it should appear be returned by the query that looks at everything created after <code>350</code>.</p> <p>What behavior do you expect?</p> <p><strong>Additions to updates:</strong></p> <p>This is a bug.</p> <p>This bug was filed for the shark rendering engine. New engine (spark) has this issue solved and will be released in the next Meteor release. (maybe 0.7)</p> <p>The bug happens when you pass a minimongo cursor as a template data context. It's very unusual way to get data to templates. I think that's why it existed for so long but was not spotted.</p> <p>The temporary workaround is to not pass cursors as data context. Instead you can pass id or name or anything else and then have a separate template helper for callee template that returns an appropriate cursor.</p> <p>A funny thing: instead of passing cursor to a template you can embed it into #with block helper and it will work as expected:</p> <pre><code>{{#with games}} &lt;ul&gt; {{#if this.count}} {{#each this}} &lt;li class="u-margin--sm"&gt; &lt;a href="/game/show/{{_id}}" class="col-md-8"&gt;{{name}}&lt;/a&gt; &lt;/li&gt; {{/each}} {{else}} &lt;span class="t-small"&gt;No games&lt;/span&gt; {{/if}} &lt;/ul&gt; {{/with}} </code></pre> <p>And everything works :).</p> <p>Re: withFetch</p> <p>It works as expected if you use <code>length</code> instead of <code>count</code>. When you fetch, cursor returns a plain JS array, it doesn't have a <code>count</code> property but has <code>length</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload