我有 3 个不同的收藏
- 包含租金详情、addressId 和 categoryId 的租金收集
const rentItemSchema = mongoose.Schema({
title: {
type: String,
required: true
},
description: {
type: String,
required: true
},
category: {
type: mongoose.Schema.Types.ObjectId,
ref: "categories",
required: true
},
address: {
type: mongoose.Schema.Types.ObjectId,
ref: "addresses",
required: true
},
}
- 地址收集
const addressSchema = new mongoose.Schema({
streetNumber: {
type: String,
max: 200
},
locality: {
type: String,
max: 200
},
landmark: {
type: String,
max: 200
},
country: {
type: String,
max: 5
},
postalCode: {
type: String,
max: 6
},
location: {
type: {
type: String,
max: 5
},
coordinates: [{
type: Number,
required: true,
default: 0,
max: 100
}]
},
)
}
- 类别集合
const categorySchema = new mongoose.Schema({
name: {
type: String,
unique: true,
// required: 'Your email/Mobile is required',
},
description: {
type: String,
max: 200
},
)
};
我想编写一个 mongo 查询,其中包含关键字、地理位置、KM 中的距离、类别并返回具有的结果集
rentitem.Title ="Keyword" ,
rentitem.address.location = "geolocation" and under given KM distance ,
rentitem.category.name = "Category"
我对 MongoDB 查询编写完全陌生,请帮助我并指导我如何编写查询。