Publish getting truncated somehow?

Hi All,

This has me stumped. I have a collection called docs. Pretty standard. Renders like so:

The idea is, when you click on the add doco button, it adds a new document. When i add the document:

As you can see, the publication gets updated. But then it looses the new object somehow. How is this happening - it is fine on refresh. It should be noted that another publication, libs is working fine (i use it to create a tree structure for the folders.)

Thanks in advance.

Tat

Code below: I’m looking at the user. The user has a property called user.docs which is an array of all docs available to the user. When i add a new doc, the helper looks like this:

export const addDoc = (libId, treeId, doc, userId) => {
  check (libId, String);
  check (treeId, String);

  check(doc, {
    docTemplate: String,
    docVersion: {
      versionLang: String,
      versionName: String,
      versionContent: Object,
    },
  });

  const newDoc = {
    docTemplate: doc.docTemplate,
    docVersion: [
      {
        versionId: guid(),
        versionLang: doc.docVersion.versionLang,
        versionName: doc.docVersion.versionName,
        versionContent: doc.docVersion.versionContent,
        versionSiblings: [],
        versionDate: new Date(),
        versionUser: userId,
      },
    ],
  };

  // Add document to docs collection
  const newDocId = insertDoc.call(newDoc);

  // work out users who have access to the library
  // then add into thier docs field.
  let usersToUpdate = getUsersInLibrary(libId);

  usersToUpdate.map((x) => {
    addDocToUser(x, newDocId);
  });

  // Add document id to library in the proper place...
  addDocToTree(libId, treeId, newDocId);

  // return the newDocId
  return newDocId;
};

Publication: This is my publication: if i do a simple return Docs.find(); it works fine. What is wrong with my publication?

import { Meteor } from 'meteor/meteor';
import { Docs } from '../docs.js';

Meteor.publish('user.docs', function() {
  if (Meteor.users.findOne({ _id: this.userId })) {
    let docs = [];

    const user = Meteor.users.findOne({ _id: this.userId });

    user.docs.map((x) => docs.push(x));

    return Docs.find({ _id: { $in: docs } });
  }

  return this.ready();
});

Hi,

So what is happening is that the publish is getting truncated as it is not reactive on the server side. Can someone show me how to solve this?

I need to do this in the publish.
(1) Look up the user.docs and get the array.
(2) Publish the list of docs which have _id in the above array.

The problem is when i add a document, my Meteor.users gets updated, but the ‘Docs’ publication does not rerun the above function, so I do not receive this downstream…

I’ve had a look at using Tracker.autorun for this, but I’m not sure how to pick this up in a react-komposer container.

Thanks in advance.

Tat