【发布时间】:2021-05-26 18:42:49
【问题描述】:
在将模型与 Mongoosastic 同步时,我收到此错误:
TypeError:无法读取未定义的属性“toLowerCase” setIndexNameIfUnset (/app/node_modules/mongoosastic/lib/mongoosastic.js:239:29)在 EmbeddedDocument.schemaIndex [作为索引] (/app/node_modules/mongoosastic/lib/mongoosastic.js:385:5) 在 EmbeddedDocument.postSave (/app/node_modules/mongoosastic/lib/mongoosastic.js:269:14) 在下一个 (/app/node_modules/kareem/index.js:198:31) 在 Kareem.execPost (/app/node_modules/kareem/index.js:217:3) 在 /app/node_modules/mongoose/lib/plugins/saveSubdocs.js:54:29 在每个 (/app/node_modules/mongoose/lib/helpers/each.js:11:5) 在 模型。 (/app/node_modules/mongoose/lib/plugins/saveSubdocs.js:53:5) 在 callMiddlewareFunction (/app/node_modules/kareem/index.js:482:23) 在 下一个 (/app/node_modules/kareem/index.js:193:9) 在下一个 (/app/node_modules/kareem/index.js:212:9) 在 Kareem.execPost (/app/node_modules/kareem/index.js:217:3) 在 _cb (/app/node_modules/kareem/index.js:307:15) 在 /app/node_modules/mongoose/lib/model.js:400:5 在 /app/node_modules/mongoose/lib/model.js:324:11 在 runMicrotasks ()
1.) orderLineItem 架构:
let orderLineItemSchema = new mongodb.Schema({
orderId: { type: String, es_indexed: true },
name: { type: String, es_indexed: true },
description: { type: String, es_indexed: true },
privateNotice: { type: String, es_indexed: true },
netPrice: { type: String, default: 0, es_indexed: true },
taxPercent: { type: Number, default: 23, es_indexed: true },
projectFile: { type: projectFileSchema, es_schema: projectFileSchema, es_indexed: true, es_type: 'nested', es_include_in_parent: true },
component: { type: [componentSchema], es_indexed: true, es_type: 'nested', es_include_in_parent: true },
additionalFiles: { type: [projectFileSchema], es_indexed: true, es_type: 'nested', es_include_in_parent: true },
status: { type: orderLineItemStatusSchema, es_indexed: true },
accepted: { type: Boolean, default: false, es_indexed: true },
archived: { type: Boolean, default: false, es_indexed: true }
}, {
timestamps: true
});
2.) projectFileSchema:
let projectFileSchema = new mongodb.Schema({
name: { type: String, es_indexed: true },
mimeType: { type: String, es_indexed: true },
path: { type: String, es_indexed: true },
archived: { type: Boolean, default: false, es_indexed: true }
});
3.) 组件架构:
let componentSchema = new mongodb.Schema({
name: { type: String, es_indexed: true },
category: { type: String, es_indexed: true },
componentId: { type: String, es_indexed: true },
symbol: { type: String, es_indexed: true },
archived: { type: Boolean, default: false, es_indexed: true }
});
4.) orderLineItemStatusSchema:
let orderLineItemStatusSchema = new mongodb.Schema({
name: {
type: String,
default: 'Utworzony'
}
}, {
timestamps: true
});
5.) 我的同步代码:
const synchronize = (model) => {
let stream = model.synchronize();
stream.on('data', function(err, doc){
// Logging success to the console
});
stream.on('close', function(){
// Logging ...
});
stream.on('error', function(err){
console.log(err);
});
}
module.exports = synchronize;
6.) 以下是我的使用方法:
const mongodb = require('mongoose');
const mtastic = require('mongoosastic');
const esClient = require('../dependencies/elasticsearch');
const orderLineItemSchema = require('../schemas/OrderLineItem/OrderLineItem');
const synchronizer = require('../helpers/synchronizer'); // This is the synchronization function
orderLineItemSchema.plugin(mtastic, {
esClient: esClient
});
let OrderLineItem = mongodb.model('OrderLineItem', orderLineItemSchema);
let interval = setInterval(() => {
synchronizer(OrderLineItem);
}, 10000);
module.exports = OrderLineItem;
这与我在应用程序中同步其他模型的方式完全相同,但只有这个会返回该错误。
我该如何解决这个问题?
【问题讨论】:
-
你能得到一个“更完整”的堆栈跟踪吗?
-
@JoeSorocin 遗憾的是,我现在没有完整的堆栈跟踪,因为在我从 MongoDB 中删除所有内容然后重新启动所有内容之后,此错误停止发生。这显然不是解决方案,我只是需要应用程序正常工作以进行演示。
-
我听到了,但我们需要更多细节来调试它。
-
@JoeSorocin 我设法得到了同样的错误。现在我用 Node 给我的完整堆栈跟踪编辑了这个问题。
-
能否请您展示一下
orderLineItemSchema的样子?
标签: node.js mongodb express elasticsearch mongoosastic