mongodb - 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;
});
我不知道,我做错了什么。看起来,那个包没有安装......?
解决方案
推荐阅读
- javascript - 你如何清理上传的图像
- powershell - 如何获取 Azure DSC 配置以读取名称为参数的自动化帐户变量?
- node.js - Firestore + Passport.js 会话功能
- c# - UWP 已绑定复选框是否已选中?
- docker - 无法连接到虚拟机 Docker
- javascript - 使用“margin:auto”时不尊重“pointer-event:none”
- python - 如何使用python将xml存储到xlsx
- arrays - 设置 Azure 位置策略限制
- git - 如何在一台开发机器上拥有多个 git 帐户?
- c# - 在 Unity 中获取 Gizmo 位置