Mongoose/Mongo structure for a data map Mongoose/Mongo structure for a data map mongoose mongoose

Mongoose/Mongo structure for a data map


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.