Encountering an issue where I am receiving a "post.save is not a function" error when trying to use the .save() function with astronomy v2. The error occurs when attempting to call the .save() function to insert a new document into the database using a Meteor methods call from the client side.
Below is some code snippet for reference:
import { Class } from 'meteor/jagi:astronomy';
import { Mongo } from 'meteor/mongo';
const Posts = new Mongo.Collection("Posts");
const Post = Class.create({
name: 'Post',
Collection : Posts,
secured: true,
fields: {
title: String,
published: Boolean,
/* ... */
},
methods: {
rename(title) {
// Check if a given user can rename this post.
if (this.ownerId !== Meteor.userId()) {
throw new Meteor.Error(403, 'You are not an owner');
}
this.title = this;
this.save();
},
publish() {
// Check if a given user can publish this post.
if (this.ownerId !== Meteor.userId()) {
throw new Meteor.Error(403, 'You are not an owner');
}
if (this.published) {
throw new Meteor.Error(403, 'Post is already published');
}
this.published = true;
this.save();
}
}
});
Meteor.methods({
"newPost"(){
const post = new Post();
post.title = "test";
post.save();
},
"renamePost"(postId, title) {
const post = Post.findOne(postId);
post.rename(title);
},
"publishPost"(postId) {
const post = Post.findOne(postId);
post.publish();
}
});
I have followed the samples provided in the astronomy documentation along with adding an additional method called newPost.
All attempts to call these functions result in an Exception:
TypeError: post.save is not a function
I have tried various solutions to resolve this error without success:
Removing and re-adding astronomy
Rebuilding the meteor project
Updating to the latest version 2.1.2
Thank you for any assistance or solutions!