Unable to insert after removing autopublish and insecure packages

Hi,

I’m very new to Meteor and I am having trouble inserting data to my collection after removing the autopublish and insecure packages. I have a simple schema in lib/collections/Weights.js:

Weights = new Mongo.Collection("Weights"); Weights.attachSchema(new SimpleSchema({ weight: { type: Number, label: "Weight (lbs)", optional: false } }));

I have the following template in client/mainTabs.html:

<template name="mainTabs"> {{#basicTabs name="" tabs=tabs}} {{#tabContent slug="weights"}} <h2>Log Weight</h2> {{> quickForm collection="Weights" template="bootstrap3-horizontal" label-class="col-sm-2" input-col-class="col-sm-10" id="InsertWeight" type="method" meteormethod="addWeight" resetOnSuccess=true}} {{/tabContent}} {{/basicTabs}} </template>

And I call this template from within client/main.html
{{> loginButtons}} {{#if currentUser}} {{> mainTabs}} {{/if}}

In client/main.js, I have a mainTabs Template helper that subscribes to the data:
weights: function() {return Meteor.subscribe("Weights");}

And finally, on the server side, I have server/main.js:
Meteor.startup(() => { Meteor.publish('Weights', function() { return Weights.find(); }); Meteor.methods({ addWeight: function(doc) { check(doc, Weights.simpleSchema()); Weights.insert(doc, function(err, docID) {console.log("DocID: ", docID);}); } }); });

I am able to type in a weight, but when I click submit, the weight does not get stored. The console.log(docID) will correctly print out the weight I typed in, so it seems that there is an issue with inserting. I’m not sure what is going wrong. Why am I not able to insert? Thanks for the help!

So, the docId should be the _id of the doc, not the value typed in? Also, I don’t think it’s an issue with the insert so much as your subscription. In your mainTabs.js, try:

Template.mainTabs.onCreated(function () {
  let self = this;
  self.autorun(function () {
    self.subscribe('Weights');
  });
});

Template.mainTabs.helpers({
  weights () {
    return Weights.find();
  }
});

I’m not exactly sure what packages you’re using, but I’ve never seen a package take a subscription as the helper.

You likely need to set your allow/deny rules for the collection if you have not already done so.