我让Mongoosastic在Keystone中开发了一些模型,并且可以使用以下命令进行更新:

Test.schema.plugin(mongoosastic);

但是,当我尝试同步/索引现有集合(https://github.com/mongoosastic/mongoosastic#indexing-mongoose-references)的记录方法以便提取所有先前的条目时:
BookSchema.plugin(mongoosastic);

var Book = mongoose.model('Book', BookSchema)
  , stream = TestSchema.synchronize()
  , count = 0;

stream.on('data', function(err, doc){
  count++;
});
stream.on('close', function(){
  console.log('indexed ' + count + ' documents!');
});
stream.on('error', function(err){
  console.log(err);
});

我收到一个错误:
var TestSchema = mongoose.model('Test', Test)
           ^

ReferenceError: mongoose is not defined

显然,这是行不通的,所以我尝试用mongoose.model替换keystone.list ...
stream = keystone.list('Test').synchronize();

但是后来我挥霍了一下:
ReferenceError: Unknown keystone list {"paths":{"_id":{"path":"_id","instance":"ObjectID","validators":[],"setters":[null],"getters":[],"options":{"auto":true},"_index":null},"slug":{"enumValues":[],"regExp":null,"path":"slug","instance":"String","validators":[],"setters":[],"getters":[],"options":{"index":{"unique":true}},"_index":{"unique":true}},"createdAt":{"path":"createdAt"

完成时:
if (!ret) throw new ReferenceError('Unknown keystone list ' + JSON.stringify(arg));
                  ^

ReferenceError: Unknown keystone list "Test"

似乎应该很简单...有人知道我所缺少的吗?请。任何帮助是极大的赞赏!粉丝们。

最佳答案

如果要从TestSchema同步数据,则应使用:
var stream = TestSchema.model.synchronize()或者,如果您想从梯形失真列表中获取它:
var stream = keystone.list('Test').model.synchronize()
重要的是,您只能在模型上调用sychronize方法。

希望这可以帮助!

09-30 20:12
查看更多