Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to subscribe to changes by field within a single document
    primarykey
    data
    text
    <p>I'm trying to figure out the correct pattern for subscribing to specific changes within a single document. An example will better highlight what I'm trying to do. Say, I have a Mongo document for a blog post, which in turn contains a list of comments. Right now, I have a query to find that blog post: <code>Posts.findOne("&lt;id"&gt;)</code>, which reactively updates my template:</p> <pre><code>&lt;template name="post"&gt; &lt;h1&gt;{{title}}&lt;/h1&gt; {{#each comments}} {{&gt; comment this}} {{/each}} &lt;/template&gt; </code></pre> <p>The issue is that when anything changes at all about that post (generally the comments list as people add them), everyone who's viewing that post will have the whole thing refresh. I'd rather 1) setup some sort of listener that's field specific, and/or 2) do a bit of manual intercepting to say "when post updates, check to see what's updated, and update something dependent on what's changed (e.g. only update the comment that's been updated, or, looks like there's a new record - let's add it)".</p> <p>I know this sort of thing is doable at the document level using <code>Collection.observe</code> (e.g. as new documents come and go, you have granular control to see what changed), but what about within documents? I think I could do it by storing my current document in a Session, and then when the document updates and I'm notified by reactive find command, compare new document to old one, but is that the best way? Am I missing something obvious?</p> <p>Any guidance is much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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