I have schema like
const propertiesSchema = new Schema({
name: {
type: String,
required: true
},
shortDescription: String,
totalArea: String,
address: {
type: mongoose.Schema.Types.ObjectId,
ref: "Address",
required: true
}
})
and the address schema like this
const addressSchema = new Schema({
addressLine1: {
type:String,
required:false
},
addressLine2: {
type:String,
required:false
},
city:{
type:mongoose.Schema.Types.ObjectId,
required:true,
ref:"City"
}
})
and i want to search city from propertiesSchema am using mongoose for the mongodb. and also i have optional searchData object like
searchData = {
"name":"test"
"city":"5c8f7f178dec7c20f4783c0d"
}
here the city id may be null and i need if the city id not null then only need to search city on propertiesSchema . please help to solve this problem. thank you..