【发布时间】:2020-04-27 18:39:43
【问题描述】:
[![在此处输入图像描述][1]][1]最初我将其划分为一个模式,但后来删除了它们并将它们简单地嵌套在我的整个文档中。我尝试将索引放在所有内容上并将它们从坐标删除到位置。我认为可能存在问题,因为这些点是嵌套的。当我运行 get Indexes 时,它显示 location.point 上有一个索引。 不管它一直说它们不是索引。我是 MERN 的新手。我不确定我在这里缺少什么。如何修复此错误,以便 GeoNear 在嵌套文档中找到索引。如您所见,我使用的是点表示法并添加了索引。
user: {
type: Schema.Types.ObjectId,
ref: "User"
},
published: {
type: Boolean,
default: false
},
placeType: placeTypeSchema,
capacity: {
maxGuestSize: Number,
rooms: Number
},
bathrooms: Number,
location: {
streetAddress: String,
suite: String,
country: String,
city: String,
state: String,
zip: String,
point: {
type: {
type: String,
default: "Point",
index: '2dsphere'
},
coordinates: {
type: [Number],
index: '2dsphere'
//index: '2dsphere'
}
}
},
amenities: {
regular: [String],
safety: [String]
},
sharedSpaces: [String],
imageUrl: String,
description: {
description: String,
hostAvailablity: String,
spaceDetails: String,
neighborhood: String,
transportation: String
},
title: String,
mobileNumber: String,
houseRules: houseRulesSchema,
preference: {
rentedLocationBefore: Boolean,
howOftenGuests: String
},
notice: {
guestNoticeTime: Number,
checkInTime: Date
},
advance: Number,
lengthOfStay: {
min: Number,
max: Number
},
price: {
basePrice: Number,
minPrice: Number,
maxPrice: Number
}
});
SpotSchema.index({"location.point": "2dsphere"});
Spot = mongoose.model('Spot', SpotSchema);
module.exports = Spot; ```
[![enter image description here][2]][2]
[1]: https://i.stack.imgur.com/2hpSE.png
[2]: https://i.stack.imgur.com/gevTo.png
【问题讨论】:
标签: javascript node.js reactjs express mongoose