I am currently learning Meteor and doing so by writing an app that allows for creatings posts and then adding tags (like #meteor) to them.
I’m currently stuck on inserting a new document into my collection. My goal is to insert the content of the post and all tags that were included. The tags have been parsed out of the post content and added to a tags array.
Here is where I am calling the insert:
Template.newPost.events({
"cick .save": function(event){
var hashtagPattern = /#[A-Za-z0-9_]*/gi;
var postContent = event.target.value;
var tags = postContent.match(hashtagPattern);
Meteor.call('newPost', postContent, tags);
event.target.value = "";
});
This is the Mongo Insert. The insert works fine without the “$push … tags” line.
The formatting of that line is based on : http://docs.mongodb.org/manual/reference/operator/update/each/
With it, I get errors such as “While building the application … Unexpected token {”
Meteor.methods({
newPost: function(postContent,postContentTags){
Posts.insert({
content: postContent ,
createdAt: new Date() ,
{ $push: { tags: {$each: postContentTags }}}
});
Since this clearly is incorrect, what is the correct way of inserting an array of elements (in this case tags) into a collection?
Any help or advice would be very much appreciated!