Note that there are some explanatory texts on larger screens.

plurals
  1. POMeteor insert into collection appears to work, but remains empty
    text
    copied!<p>I'm doing a simple insert into a meteor collection that appears work, but leaves the collection empty.</p> <p>The collection is defined properly on the server:</p> <pre><code>Meteor.publish("comments", function () { return Comments.find(); }); </code></pre> <p>Subscribed to properly in the client.js:</p> <pre><code>Meteor.subscribe("commments"); </code></pre> <p>And set up properly on the model.js:</p> <pre><code>Comments = new Meteor.Collection("comments"); </code></pre> <p>The insert code is as follows:</p> <pre><code>Meteor.methods({ addComment: function (options) { check(options.post_id, String); check(options.comment, NonEmptyString); if (! this.userId) throw new Meteor.Error(403, "You must be logged in to comment."); if (options.comment.length &gt; 1000) throw new Meteor.Error(413, "Comment is too long"); var post = Posts.findOne(options.post_id); if (! post) throw new Meteor.Error(404, "No such post"); // add new comment var timestamp = (new Date()).getTime(); console.log('Comment: ' + options.comment); console.log('Post: ' + options.post_id); console.log('UserId: ' + this.userId); var saved = Comments.insert({ owner: this.userId, post_id: options.post_id, timestamp: timestamp, text: options.comment}); console.log('Saved: ' + saved); } }); </code></pre> <p>Once the insert is called, the console prints out the following:</p> <pre><code>Comment: Something Post: xRjqaBBEMa6qjGnDm UserId: SCz9e6zrpcQrKXYWX Saved: FCxww9GsrDsjFQAGF &gt; Comments.find().count() 0 </code></pre> <p>I have inserts into several other collections that work just fine (Posts being one of them as you can see the post ID in the code). In the docs ist said that if the insert errors out it will print to the console, but as you can see it appears to be working, yet is actually empty.</p> <p>Thanks.</p> <p>UPDATE: I did find that the data is being put into the database, but for some reason is not showing up. I'm not sure why the data is not being published properly since there are no filters on the find().</p>
 

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