【问题标题】:mongoose don't create 2dsphere index in mongodb atlasmongoose 不在 mongodb atlas 中创建 2dsphere 索引
【发布时间】:2021-10-25 06:15:10
【问题描述】:

我无法在 MongoDB atlas 中创建 2dsphere index。我已经在我的本地主机 MongoDB 中创建了。但我不知道为什么它不会在 Anastasia MongoDB 中创建?

import mongoose from "mongoose";

const { Schema } = mongoose;

const schema = new Schema(
  {
    location: {
      type: {
        type: String,
        required: true
      },
      coordinates: {
        type: [Number],
        required: true
      },
    }
  },
  { timestamps: { createdAt: "createdAt" } },
);

schema.index({ location: "2dsphere" });
schema.index({ "location.coordinates": "2d" });

const Apartment = mongoose.model("Apartment", schema,);

export default Apartment;

【问题讨论】:

    标签: mongodb mongodb-atlas


    【解决方案1】:

    最后,我通过将 mongoose 降级到 5.3.6 版来解决问题

    【讨论】:

      猜你喜欢
      • 2019-03-10
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 2013-06-09
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      相关资源
      最近更新 更多