首页 > 解决方案 > Meteor Collection Hooks 错误:“Collection<>”类型上不存在属性“之前”

问题描述

我正在尝试在我的项目中集成流星收集钩子。我安装了它:

meteor add matb33:collection-hooks

并将其添加到 tsconfig.json:

 "types": [
            "meteor-typings",
            "@types/underscore",
            "@types/meteor-collection-hooks"
        ]

在 package.json 的依赖项中,我有:

  "@types/meteor-collection-hooks": "^0.8.3",

在problems.collection.ts中的both/collection中我有方法“Problems.before.insert”-“之前”加了下划线并显示了我在标题中写的错误。(此方法从最后插入的对象中获取 problemId,增加它,并将增加的 Id 插入新的创建对象)。problem.collection.ts 中的代码:

import { MongoObservable } from "meteor-rxjs";
import { Problem } from "../models/problem.model";


export const Problems = new MongoObservable.Collection<Problem>("problems");



function loggedIn() {
    return !!Meteor.user();
  }

Problems.allow({
    insert: loggedIn,
    update: loggedIn,
    remove: loggedIn
});


Problems.before.insert(function (problemId, problem) {
    let lastProblem = Problems.find({}, { sort: { _id: -1 }, limit: 1 }).fetch()[0];
    let lastProblemId = lastProblem.problemSecondId++;
    problem.problemSecondId = lastProblemId;
});

我不知道,我做错了什么。看起来,那个包没有安装......?

标签: mongodbmeteorcollectionshook

解决方案


推荐阅读