mongoose-elasticsearch-xp icon indicating copy to clipboard operation
mongoose-elasticsearch-xp copied to clipboard

[Bag] TypeError: Cannot read property 'toLowerCase' of undefined

Open IlyaShkurenko opened this issue 3 years ago • 0 comments

require('mongoose-double')(mongoose);

const Schema = mongoose.Schema;
const Double = Schema.Types.Double;

const productSchema = new Schema(
  {
    isCloseout: { type: Boolean, required: true, index: true, default: false },
    isCaution: { type: Boolean, required: true, index: true, default: false },
    isOnDemand: { type: Boolean, required: true, index: true, default: false },
    isHazmat: { type: Boolean, required: true, index: true, default: false },
    productId: { type: String, required: true, index: true, es_indexed: true, es_type: 'text' },
    productName: { type: String, required: true, index: true, es_indexed: true, es_type: 'text' },
    slug: { type: String, required: true, index: true, unique: true, es_indexed: true, es_type: 'keyword' },,
    priceMax: { type: Double, index: true },
    priceMin: { type: Double, index: true },
    status: { type: String, index: true, es_indexed: true, es_type: 'text' }
  },
  { timestamps: true }
);

there is error in function because It can't detect Double type instance for field priceMax and priceMin even if it's not marked as es_index: true

module.exports.getType = function getType(path) {
  return (path.caster && path.caster.instance
    ? path.caster.instance
    : path.instance
  ).toLowerCase();
};

IlyaShkurenko avatar Mar 31 '21 18:03 IlyaShkurenko