数据映射的Mongoose/Mongo结构 [英] Mongoose/Mongo structure for a data map

查看:96
本文介绍了数据映射的Mongoose/Mongo结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一些数据,我想寻求一些帮助以找到正确的数据结构来显示它.我的目标是要有一张上面的图片一样的地图.不同的物理站点将具有纬度和经度信息,但是圆形半径将由每个站点的不同统计信息确定.用户将能够选择他们想要查看的数据集.大约有26组数据.只有一组位置.

Hi there, I have some data, and I'd like some help with finding the correct data structure for displaying it. My goal is to have a map like the image above. Different physical sites will have the latitude and longitude information, but the circular radius will be determined by different statistics at each site. The user will be able to select which set of data they'd like to see. There are approximately 26 sets of data. Only one set of locations.

我的数据如下:

位置(约5000件)

var locSchema = mongoose.Schema({
 name : 'string',
 siteID : 'number',
 address1 : 'string',
 address2 : 'string',
 loc: {type: [Number], index: '2dsphere'}
});

特定数据(约12000件)

Specific Data (approximately 12000 pieces)

var dataSchema = mongoose.Schema({
  providerNumber : "number",  //The "siteID" of the site.
  date : "date",
  volume : "number",
  cost : "number",
  label : "string",  //There are 26 different stats each with a different label
  siteID : "oid"  //The oid of the site
});

我的第一个猜测是它们应该是一个单一集合,每个数据都存储为一个数组:

My first guess was that they should be a single collection with each piece of data stored as an array:

name : 'string',
siteID : 'number',
address1 : 'string',
address2 : 'string',
loc: {type: [Number], index: '2dsphere'},
data : [
   {
     providerNumber : "number",  //The "siteID" of the site.
     date : "date",
     volume : "number",
     cost : "number",
     label : "string",  //There are 26 different stats each with a different label
     siteID : "oid"  //The oid of the site
   },
   ...
]

但是我不确定如何在Mongoose中创建这种数据结构,尤其是对象数组.另外,有可能需要将多组更新的数据可视化.

But I'm not sure how to create that kind of data structure in Mongoose, especially the array of objects. Also, there is a chance that there will be multiple sets of updated data that will need to be visualized.

所以我的问题是: 1.此数据的最佳结构是什么? 2.在Mongoose中创建它的语法是什么? 3.关于使其可扩展的任何建议吗?

So my questions are: 1. What is the best structure for this data? 2. What is the syntax for creating it in Mongoose? 3. Any advice on making it exapandable?

推荐答案

我倾向于保持mongo中的数据尽可能平坦和非规范化.我遇到了更新和维护子文档(尤其是数组)的问题.我也喜欢根据最常使用的数据来建模我的数据.我的偏好是这样的:

I have a bias towards keeping the data in mongo as flat and denormalized as possible. I have run into problems updating and maintaining subdocuments, especially arrays. I also like to model my data based off of how it's going to be used most often. My preference would be something like:

var schema = mongoose.Schema({
  name: String,
  siteID: Number,
  address1: String,
  address2: String
  loc: { type: [Number], index: '2dsphere' }
  date: Date,
  volume: Number,
  cost:  Number,
  label: String
});

这意味着您将要重复一些数据(名称,地址1等),但是我认为如果要比locSchema更多地操作dataSchema部分,那是值得的.现在,添加/删除/更新数据要简单得多.您可以根据需要使用 mongo聚合来对数据进行分组和结构化.

This means you're going to have some duplication of data (name, address1, etc), but I think it's worth it if you're manipulating the dataSchema portion more than you are the locSchema. It's now much simpler to add/remove/update data. You can use mongo aggregation to group and structure the data however you would like.

这篇关于数据映射的Mongoose/Mongo结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆