1

我让 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"

似乎应该很简单......有人知道我错过了什么吗?请。任何帮助是极大的赞赏!粉丝。

4

1 回答 1

0

如果你想同步你的数据,TestSchema你应该使用:

var stream = TestSchema.model.synchronize() 或者如果你想从 keystone 列表中获取它:

var stream = keystone.list('Test').model.synchronize()

这里重要的是你sychronize只能在模型上调用方法。

希望这可以帮助!

于 2016-05-05T11:05:25.323 回答