我有两个收藏品商场和商店。我想保存它们的位置信息(如纬度和经度)。对于购物中心来说,这很容易,因为它们只有一个位置信息,所以我可以定义纬度和经度属性。但是对于商店来说,他们可以是在商场里,也可以是在街上,而且他们有多个地点。我想保持商铺和购物中心之间的关系,因为他们在购物中心内的地方。我想把地点作为一个单独的集合来保存(至少对于商店来说是这样),否则当我列出商店的时候,数据会很重。只有在必要时才会显示(下载)选定商店的位置。所以问题是,地点收集的数据模型应该是怎样的?我正在考虑这样的事情,但我觉得这不是最好的主意。为了简单起见,我考虑将购物中心的lat、lan数据直接保存在它的集合中(顺便说一句,我使用了简单的模式):
ShopLocations = new Mongo.Collection('shoplocations');
var shopsLocationsSchema = new SimpleSchema ({
name: {
type: String,
label: 'Location Name',
max: 200
},
inMall: {
type: Boolean,
label: 'Is it in the mall?',
optional: true
},
mallId: {
type: String,
label: 'Mall ID',
optional: true
},
latitude: {
type: Number,
label: 'Latitude',
decimal: true,
optional: true
},
longitude: {
type: Number,
label: 'Latitude',
decimal: true,
optional: true
}
});
ShopLocations.attachSchema(shopsLocationsSchema, {replace: true});发布于 2015-03-26 03:27:57
我想你有三个收藏品:购物中心、商店和地点。
商场和商店都可以有地点,即使购物中心只有一个。
地点要么是商店,要么是商场,要么是商场里的商店。
我会简单地将一个位置建模为storeId, mallId, latitude, longitude,然后使用storeId的脓肿来表示该位置只属于一个购物中心。与商店相对应的位置文档至少有storeId,但只有当该位置位于购物中心内时,才会有mallId。
关于MongoDB的好处是,您可以查询键及其值的存在与否。例如:
查找所有商场的位置:
Locations.find({mallId: {$exists: true}, storeId: {$exists: false}});查找不在商场的所有商店的位置:
Locations.find({mallId: {$exists: false}, storeId: {$exists: true}});查找商场内所有商店的位置:
Locations.(mallId: {$exists: true}, storeId: {$exists: true}});https://stackoverflow.com/questions/29254473
复制相似问题