Please i am trying to wrap my head over how to query a collection dynamically. I have a collection that has the below schema.
Tripart_Property_Schema = new SimpleSchema({
"type" : {
type : String,
label : 'Property type',
},
"sale_lease" : {
type : String,
label : '',
},
"location" : {
type : Object,
label : '',
optional : true
},
"location.state" : {
type : String,
label : 'state',
},
"location.lga" : {
type : String,
label : 'lga',
optional : true
},
"location.address" : {
type : String,
label : 'address',
optional : true
},
"amount" : {
type : Object,
label : '',
optional : true
},
"amount.amount" : {
type : Number,
label : '',
optional : true
},
"amount.discount" : {
type : Number,
label : '',
optional : true
},
"active" : {
type : Boolean,
label : '',
optional : true
},
"views" : {
type : Number,
label : '',
optional : true
},
"date_added" : {
type : Date ,
label : '',
optional : true
},
"general_features" : {
type : [String],
label : '',
optional : true
},
"outdoor_features" : {
type : [String],
label : '',
optional : true
},
"indoor_features" : {
type : [String],
label : '',
optional : true
},
"other_facilities" : {
type : Object,
label : '',
optional : true
},
"other_facilities.bedroom" : {
type : Number,
label : '',
optional : true
},
"other_facilities.bathroom" : {
type : Number,
label : ' ',
optional : true
},
"other_facilities.garage" : {
type : Number,
label : '',
optional : true
},
"other_facilities.staffQuaters" : {
type : Number,
label : '',
optional : true
}
});
I have created a user interface where a user can query the data using any combination of the available fields. A user can make a query searching for a property by using the sale_lease field, amount.amount field and also query the general_features field which is an array. I don't know how to generate this query based on the user selected preference. I know how to perform the query knowing the fields queried before hand, but making it dynamic is where the problem lies.
I am trying to make use of multiple if statements to possibly make a query for all possible combination of fields, but i kind of realize that this is not the way to achieve this. I will be very grateful if i can be pointed to the right direction.