由于某种原因,我得到了一个"post "。在天文学v2上使用. Save()函数时,Save不是一个函数。我试图调用.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的附加方法。
调用这些函数都会导致一个异常
TypeError:职位。保存不是一个函数
已尝试以下方法解决错误,但没有成功
删除并重新添加天文学
Rebuild meteor project
更新到最新2.1.2版本
谢谢你的回答!
看起来method不了解Astronomy.Class。你输出你的课程?