Meteor Infinity: the astronomy .save functionality seems to be malfunctioning

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!

Answer №1

Seems like the method isn't aware of Astronomy.Class. Have you properly exported your class?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Mapping arguments as function values

Hello there, I have an array of objects that I am attempting to map through. const monthObject = { "March 2022": [ { "date": "2022-03-16", "amount": "-50", &q ...

I would like to request information regarding PHP

I am attempting to retrieve information from a PHP file and insert HTML code into the <div id="1"..., but there are no errors showing and nothing is being inserted into the div. Could the issue be with the AJAX code or is it a problem within the HTML st ...

Utilize recursive and for loop methods for parsing JSON efficiently

I have a JSON file that requires parsing. I'm attempting to implement a recursive method for this task. The current JSON data is structured as shown below: Item 01 SubItem 01 InnerSubItem 01 Item 02 SubItem 01 InnerSubItem 01 Unfortunately, t ...

Modifying input values in AngularJS/HTML

I'm encountering an issue with the ng-repeat function in AngularJS within my HTML code. The problem is that when I change the input with the ID 'add-price' in one cartproduct, it simultaneously changes in all other cartproducts as well. For ...

Incorporate a directive dynamically within a separate directive

Introducing the table-div directive, which is responsible for rendering both the header and body of a table. Each row within tbody has the option to incorporate additional functionality through a custom directive that can display data linked to its parent ...

[Web Development]:

Having an issue with my HTML file where a JavaScript function named "CheckCaptcha" is not being executed when an image is clicked. I've been working on the code for hours, trying different tweaks and modifications, but it still can't seem to find ...

Convert a Twitter Direct Message Link by changing the `<button>` tag to an `<a>` tag

When you log into Twitter and have Direct Message enabled, a "Send Message" button will appear. Can someone please provide the URL for sending a DM to a specific user? I tried looking at the code but I could use some assistance. Any thoughts? Thank you in ...

bespoke filter designed to conceal any negative figures

I am trying to implement a feature where a text box will display nothing if the ng-model contains a negative value. I want the ng-model to remain unchanged while ensuring that negative values are not displayed. I am looking for a custom filter to achieve t ...

Utilizing jQuery to dynamically update background colors within an ASP repeater based on the selected value of a dropdown list

On my asp.net web page, I have a repeater that displays a table with various fields in each row. I am trying to make it so that when the value of a dropdown within a repeater row changes, the entire row is highlighted in color. While I have achieved this s ...

Is there a difference between innerHTML strings and their corresponding strings in JavaScript?

I am facing an issue with a code snippet that seems to have an unusual error. The following code is a simplified version to demonstrate the strange behavior. <html> <head> <script type = "text/javascript"> window.onload = fun ...

Unsupported file format for Three.js FBX Binary model

I am currently working with three.js in a mobile application that is built using JavaScript. I am trying to incorporate a 3D model using an .fbx file, but I am facing issues with the binary format not being supported by FBXLoader. As someone who doesn&apos ...

Is there a way to retrieve files stored on my hard drive within a webpage?

I have a large number of files stored on my hard drive, all following the same format, 2014.C1.012.012 - full name of the file. They each have unique numbers and names. I want to create a local webpage where I can organize these files into a table w ...

Tips for preventing multiple requests in your JavaScript search autocomplete feature

I'm currently using the Turbolinks.visit action with the help of $(document).on("input");... HTML <form id="mainSearch" method="get" autocomplete="off"> <input type="search" name="s" placeholder="Search" /> </form> Javascript ...

Using JavaScript to add a Vue component and display it on a page

I am working with a Vue component that is imported in a component file. My goal is to render another component using the append function. How can I achieve this? <template> <JqxGrid :width="width" :source="dataAdapter" :columns="gridValues" ...

Alter the position of the anchor object in the center using JavaScript upon page load

When my page loads, I want to automatically jump to a specific anchor tag and ensure that the anchor object is centered in the window. Initially, I implemented a basic function to achieve this: <body onload="goToAnchor();"> <script type="text/ja ...

Exploring the importance of defining a JSONP callback function

I am relatively new to JavaScript and struggling with an issue in my code. My code includes an Ajax request to a server, and I receive a response from it. Due to the cross-domain nature of the request, I am utilizing JSONP. $.ajax({ url: "***", c ...

The repetition of the react nodejs page load occurs when the get method is utilized

I've successfully set up a page and function for loading the customer list. However, I'm facing an issue where adding the get method to my code results in it being called every time information is received from the URL and the page is rendered. i ...

Executing asynchronous JavaScript code within a Golang request: a comprehensive guide

I am in need of a solution to retrieve the content from dynamically generated pages using ajax on a website, specifically with code written in golang. I have found examples for non-ajax pages but struggling to find one that works for ajax pages. Any guid ...

Dynamically populate the dropdown options in Angular as the dropdown is selected during runtime

I have a JSON object that holds the names of different dropdowns. It looks something like this - $scope.dropdowns = { "dp1" :{}, "dp2" :{} } The objects dp1 and dp2 correspond to their respective dropdown menus. These objects will be used by th ...

When the child element's "aria-expanded" attribute is set to true, a CSS class should be dynamically

Is there a way to apply a grey background to the first div when the dropdown is open? I've managed to add CSS based on the child elements' aria-expanding attribute, but I'm unsure how to do it for a parent element. Since I am using Vue, I pr ...