首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mongoosastic: TypeError:无法读取未定义的属性“toLowerCase”

Mongoosastic: TypeError:无法读取未定义的属性“toLowerCase”
EN

Stack Overflow用户
提问于 2021-02-24 12:32:22
回答 2查看 905关注 0票数 0

当使用蒙哥拉斯同步模型时,我收到了以下错误:

(/app/node_modules/mongoosastic/lib/mongoosastic.js:239:29) at EmbeddedDocument.schemaIndex as指标 at EmbeddedDocument.postSave (/app/node_modules/mongoosastic/lib/mongoosastic.js:269:14) at next (/app/node_modules/kareem/index.js:198:31)在/app/node_modules/mongoose/lib/plugins/saveSubdocs (/app/node_modules/kareem/index.js:217:3)处读取未定义的属性“toLowerCase”。在模型的每个(/app/node_modules/mongoose/lib/helpers/each.js:11:5)的.js:54:29。(/app/node_modules/mongoose/lib/plugins/saveSubdocs.js:53:5) at callMiddlewareFunction (/app/node_callMiddlewareFunction/kareem/index.js:482:23)下一个(/app/node_callMiddlewareFunction/kareem/index.js:193:9),下一个(/app/node_callMiddlewareFunction/kareem/index.js:212:9)在_cb (/app/node_ Kareem.execPost /kareem/index.js:217:3)。:307:15) at /app/node_modules/mongoose/lib/model.js. at :400:5在/app/node_modules/mongoose/lib/model.js:324:11 at runMicrotasks ()

( 1.)orderLineItem模式:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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.)组件模式:

代码语言:javascript
复制
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:

代码语言:javascript
复制
let orderLineItemStatusSchema = new mongodb.Schema({
    name: {
        type: String,
        default: 'Utworzony'
    }
}, {
    timestamps: true
});

( 5.)我的同步代码:

代码语言:javascript
复制
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.)下面是我如何使用它:

代码语言:javascript
复制
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;

这是完全相同的方式,我同步其他模型在我的应用程序,但只有这个返回的错误。

我怎么才能解决这个问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-22 23:49:57

在Mongoosastic存储库中有 问题关闭,没有解决方案,这表明这很可能是库中的一个bug,在用户代码中可能没有解决方案。

这些问题与您的共同之处在于子文档的使用,快速浏览库的源代码就会发现,它可能确实与不正确地处理这种情况有关。

查看库的测试套件也没有显示任何涉及此场景的测试,进一步表明它可能根本不受支持。

票数 1
EN

Stack Overflow用户

发布于 2021-03-11 13:39:07

现在还不清楚从源代码为什么modelName会是undefined.

无论如何,每个mongoosastic模型构造函数都是参数,所以在注册插件时我会声明它:

代码语言:javascript
复制
...
orderLineItemSchema.plugin(mtastic, {
    esClient: esClient,
    index: 'orders-index`     // <---
});

let OrderLineItem = mongodb.model('OrderLineItem', orderLineItemSchema);
...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66351012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档