【发布时间】:2016-09-07 14:35:54
【问题描述】:
请让我想一想如何动态查询集合。我有一个具有以下架构的集合。
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
}
});
我创建了一个用户界面,用户可以在其中使用可用字段的任意组合查询数据。用户可以使用sale_lease 字段、amount.amount 字段查询属性,也可以查询数组general_features 字段。我不知道如何根据用户选择的偏好生成此查询。我知道如何在事先知道查询的字段的情况下执行查询,但使其动态化是问题所在。
我正在尝试使用多个if 语句来查询所有可能的字段组合,但我有点意识到这不是实现这一目标的方法。如果我能指出正确的方向,我将不胜感激。
【问题讨论】:
-
不,您能不能详细说明一下。谢谢
-
抱歉,误读了问题
标签: mongodb meteor dynamic-queries