ensureIndex要求回调

Fez*_*sta 3 mongodb node.js

我需要在MongoDB中创建一个索引来存储唯一的slug.

我使用此代码生成索引:

this._db = db;
this._collection = this._db.collection("Topics");
this._collection.ensureIndex( { slug: 1 }, { unique: true });
Run Code Online (Sandbox Code Playgroud)

但是当我运行我的测试时,它在"beforeEach"上失败了:(我正在使用mongo-clean NPM)

beforeEach(function (done) {
    clean(dbURI, function (err, created) {
        db = created;
        instance = topicManager(db);
        done(err);
    });
});
Run Code Online (Sandbox Code Playgroud)

他说:

Uncaught Error: Cannot use a writeConcern without a provided callback
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?(如果我评论ensureIndex一切正常)

E_n*_*ate 5

如响应所示,您可能需要为您的调用提供回调函数ensureIndex:

this._db = db;
this._collection = this._db.collection("Topics");
this._collection.ensureIndex( { slug: 1 }, { unique: true }, function(error) {
  if (error) {
   // oops!
  }});
Run Code Online (Sandbox Code Playgroud)