如何索引使用鉴别器的mongoose Schema上的字段?

问题描述 投票:0回答:1

我开始使用鉴别器后错误开始了。

const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const Base = require("../config/Base");

const Refill = Base.discriminator(
  "Refill",
  new Schema({
    cylinderSize: { type: Number, required: true },
    cylinderSwap: { type: Boolean, required: true },
    quantity: { type: Number, required: true },
    location: {
      type: { type: String },
      coordinates: [Number]
    }
  })
);

Refill.index({ location: "2dsphere" });


module.exports = mongoose.model("Refill");

这将返回错误Refill.index is not a function

node.js mongodb mongoose-schema
1个回答
0
投票

我刚拿出Refill.index({ location: "2dsphere" });,我的其余代码工作正常,显然索引该字段是没有必要的。

© www.soinside.com 2019 - 2024. All rights reserved.