mongoose查询一系列子文档,其中的位置需要使用半径进行过滤
这是父模式mongoose查询一系列子文档,其中的位置需要使用半径进行过滤,mongoose,mongodb-query,aggregation-framework,mongoose-schema,Mongoose,Mongodb Query,Aggregation Framework,Mongoose Schema,这是父模式 export const PuppetTeamSchema = new mongoose.Schema({ teamMemberCount: { type: Number, required: [true,'What is your current team capacity?'] }, typeOfPerformance: {
export const PuppetTeamSchema = new mongoose.Schema({
teamMemberCount: {
type: Number,
required: [true,'What is your current team capacity?']
},
typeOfPerformance: {
type: String,
required: false
},
shows: {
type: [ShowSchema],
required: false
}
}
下面是子模式
export const ShowSchema = new mongoose.Schema({
id: {
type: String,
},
showName: {
type: String,
required: true
},
location: {
type: {
type: String,
default:'Point',
required: true
},
coordinates: {
type: [Number],
required: true
}
}
});
PuppetShowSchema.index({location:'2dsphere'});
我想查询靠近用户的显示(基于用户经度和纬度)
这是我正在尝试的代码,它甚至不会编译,因为显然这段代码是错误的,但我希望这样做
this.puppetTeamModel.find({shows: { location: { $near: { $geometry: { type: "Point", coordinates: [long,lat] }, $maxDistance: parseInt('5000')}}} });
我知道这篇文章可以根据我的要求查询位置,但我需要知道如何将这段代码与显示数组关联起来
此部件可以根据用户坐标查询位置
{ location: { $near: { $geometry: { type: "Point", coordinates: [userlong,userLat] }, $maxDistance: 5000}}}
我需要将它与显示数组关联起来,并从整体上进行查询