我开始使用鉴别器后错误开始了。
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
我刚拿出Refill.index({ location: "2dsphere" });
,我的其余代码工作正常,显然索引该字段是没有必要的。