我有 3 个不同的系列
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 查询,它接受 , Keyword , geolocation , distance in KM , Category 并返回结果集
rentitem.Title ="Keyword" ,
rentitem.address.location = "geolocation" and under given KM distance ,
rentitem.category.name = "Category"
我对 MongoDB 查询编写完全陌生,请帮助我并指导我如何编写查询。