我需要在MongoDB中创建一个索引来存储唯一的slug. 我使用此代码生成索引: this._db = db;this._collection = this._db.collection("Topics");this._collection.ensureIndex( { slug: 1 }, { unique: true }); 但是当我运行我
我使用此代码生成索引:
this._db = db;
this._collection = this._db.collection("Topics");
this._collection.ensureIndex( { slug: 1 }, { unique: true });
但是当我运行我的测试时,它在“beforeEach”上失败了:(我正在使用mongo-clean NPM)
beforeEach(function (done) {
clean(dbURI, function (err, created) {
db = created;
instance = topicManager(db);
done(err);
});
});
他说:
Uncaught Error: Cannot use a writeConcern without a provided callback
我究竟做错了什么? (如果我评论ensureIndex一切正常)
如响应所示,您可能需要为您对ensureIndex的调用提供回调函数:this._db = db;
this._collection = this._db.collection("Topics");
this._collection.ensureIndex( { slug: 1 }, { unique: true }, function(error) {
if (error) {
// oops!
}});
