mongoose 不在 mongodb atlas 中创建 2dsphere 索引
mongoose don't create 2dsphere index in mongodb atlas
我无法在 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;
最后,我通过将 mongoose 降级到 5.3.6 版本解决了问题
我无法在 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;
最后,我通过将 mongoose 降级到 5.3.6 版本解决了问题