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.
My data looks like this:
Locations (approximately 5000 pieces)
var locSchema = mongoose.Schema({
name : 'string',
siteID : 'number',
address1 : 'string',
address2 : 'string',
loc: {type: [Number], index: '2dsphere'}
});
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
},
...
]
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.
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?
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
});
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.