我有此架构,我想使用字段position
查询起始位置附近的城市。
import mongoose, { Schema } from "mongoose";
var codcomSchema = new Schema({
code: String,
id: Number,
position: {
type: { type: String, enum: ['Point'], default: "Point" },
coordinates: { type: [Number], index: { type: '2dsphere' } }
}
}, { _id: false });
var citySchema = new Schema({
name: String,
code: String,
zone: String,
country: String,
cap: [codcomSchema],
});
export default mongoose.model('city', citySchema);
索引声明正确吗?
这是我进行的查询,但返回错误。
let cities = await cityModel.find({
"cap.position": {
$near: {
$maxDistance: distance,
$geometry: {
type: "Point",
coordinates: coordinate
}
}
}
});