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();
});