流星的数据模型

Data model for meteor

我有两个 collection,商场和商店。我想保留它们的位置信息(如纬度和经度)。对于商场来说,很容易,因为他们只有一个位置信息,所以我可以定义纬度和经度属性。但是对于商店来说,它们既可以在商场内,也可以在街道上,而且它们有多个位置。我想保持商店和商场之间的关系,因为它们在商场内的地方。我想将位置保留为单独的 collection(至少对于商店而言),否则当我列出商店时数据会非常大。仅在必要时才会显示(下载)所选商店的位置。所以问题是,位置 collection 的数据模型应该如何?我正在考虑这样的事情,但我觉得这不是最好的主意。为了简单起见,我考虑将商场的纬度、局域网数据直接保存在 collection 中(顺便说一句,我使用简单的模式):

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});

我认为您有三个集合: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}});