2016-08-11 60 views
2

由於某些原因,我在天文學v2上使用.save()函數得到了「post.save不是函數」。我試圖在客戶端使用流星方法調用在數據庫中插入新文檔時調用.save()。流星jagi:天文學.save功能不起作用

下面是一些代碼:

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(); 
    } 
}); 

你可以使用一個名爲newPost的其他方法的天文文檔上的樣本見IM。

調用這些函數都導致了異常

TypeError: post.save is not a function

曾嘗試在沒有成功

  • 刪除並重新加入天文學

  • 重建解決錯誤以下嘗試流星項目

  • 更新到最新版本2.1.2

Thx for the answers!

回答

0

它看起來像方法不知道天文學類。 你導出你的課程?