我让 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"
似乎应该很简单......有人知道我错过了什么吗?请。任何帮助是极大的赞赏!粉丝。