我刚刚通过以下方式安装了mongo-triggers:
npm install mongo-triggers
我正在尝试运行一个hello世界:
var MongoClient = require('mongodb').MongoClient;
var triggers = require("mongo-triggers");
MongoClient.connect('mongodb://localhost:27017/mydatabase', function(err, db) {
triggers(db.mycollection).insert(function(document, next) {
console.log("Triggered on insert");
next();
});
});
我得到:
TypeError: Cannot read property 'save' of undefined
我对js不太熟悉,所以我可能会怀念某事。有人可以帮忙吗?
最佳答案
代替
var MongoClient = require('mongodb')。MongoClient; require(“ mongo-triggers”);
尝试
var MongoClient = require('mongodb')。MongoClient;
var triggers = require(“ mongo-triggers”);