【问题标题】:Data model for meteor流星数据模型
【发布时间】:2015-03-25 11:32:19
【问题描述】:

我有两个系列,商场和商店。我想保留它们的位置信息(如纬度和经度)。对于商场来说,这很容易,因为它们只有一个位置信息,所以我可以定义纬度和经度属性。但对于商店来说,它们可以在商场内或街道上,并且有多个位置。我想保持商店和商场之间的关系,因为它们在商场内的地方。我想将位置保留为单独的集合(至少对于商店而言),否则当我列出商店时数据会非常繁重。仅在必要时才会显示(下载)所选商店的位置。所以问题是,位置收集的数据模型应该如何?我正在考虑这样的事情,但我觉得这不是最好的主意。为了简单起见,我考虑将 mall 的 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});

【问题讨论】:

    标签: javascript meteor datamodel


    【解决方案1】:

    我认为您拥有三个系列:Malls、Shops 和 Locations。

    商场和商店都可以有位置,即使商场只有一个。

    位置对应于商店、商场或商场中的商店。

    我会简单地将位置建模为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}});
    

    【讨论】:

    • 谢谢你,米切尔!这就是我要找的!如果您能提供帮助,还有一件事:如何显示不在购物中心的特定商店的位置?像这样?
    • shopsNotInMall = Locations.find({$exists: {mallId: false, storeId: storeid}});
    • shopsNotInMalls = Locations.find({storeId: myStoreId, mallId: {$exists: false}});
    猜你喜欢
    • 1970-01-01
    • 2014-08-04
    • 2016-04-06
    • 1970-01-01
    • 2014-12-30
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    相关资源
    最近更新 更多