javascript - meteor 数据模型

标签 javascript meteor datamodel

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

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

最佳答案

我认为您有三个集合:购物中心、商店和地点。

购物中心和商店都可以有地点,即使购物中心只有一个。

位置对应于商店、购物中心或购物中心中的商店。

我会将位置简单地建模为 storeId、mallId、纬度、经度,然后使用不存在的 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}});

关于javascript - meteor 数据模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29254473/

相关文章:

javascript - 在 jQuery UI Datepicker 中跳转一周或一个月

javascript - 在 javascript 生成的 HTML 中添加额外的 javascript

javascript - 使用meteor-autoform预览数据

sapui5 - 使用 ODataModel 与 JSONModel 相比有什么好处?

command-line - 使用 Cassandra 命令行界面有什么好的指南吗?

python - 为什么自定义类型接受 Python 中的临时属性(而内置函数不接受)?

javascript - 选中后的复选框在 jquery 中失去监听器

javascript - react-native-navigation 导航器是未定义的自定义按钮

meteor - 如何使用Iron Router返回404

meteor - 巴贝尔笔记 : The code generator has deoptimised the styling of "app.js" as it exceeds the max of "100KB in Meteor