2014년 12월 1일 월요일

Collection setup advice

I've chosen to store all my companies products in MongoDB because we have a wide array of different items, all with different specifications.  So far, MongoDB has worked out great for our needs because we are able to completely customize each document to fit the exact specifications for our products.

With most of our items having measurements held within the specs, I'm looking to store the value of a the measurement in separately from the unit of measure. This would allow for much easier conversion down the line. There would also be some cases where I'd have to put other information next to one of these measurements and unit of measurement.  

An example of that would be the weight of an object being 50 lbs. *Weight is without cable or another example Speed: 30 fpm - each winch

Another problem I'm running into is scenarios where I store the size of an item as being 30" x 35" x 20".  How could I cleanly store this? 

What I have right now is this:  

{
     "category" : "547295b360557a18b87c4f2f",
     "category_id_old" : "2",
     "category_grp" : "H0004",
     "old_item_id" : "6",
     "model_number" : "Brick Basket",
     "capacity" : "400 lbs.",
     "weight" : "60 lbs.",
     "size" : "30\"x20\"x12\""
}

{
     "category" : "547295b760557a18b87c4f83",
     "category_id_old" : "75",
     "category_grp" : "H00030",
     "old_item_id" : "1727",
     "model_number" : "Eye-to-Eye",
     "capacity" : "5.6",
     "wire_rope_size" : "19\' 1\"",
     "size" : " 3/4\""
}

{
     "category" : "547295b760557a18b87c4f84",
     "category_id_old" : "16",
     "category_grp" : "H00022",
     "old_item_id" : "805",
     "model_number" : "Eye-to-Eye",
     "capacity" : "4,700 lbs. (Each Winch)",
     "cfm" : 250 (Each Winch)",
     "speed" : 30 fpm. (Each Winch)"
}
 
Any guidance to how I can cleanly store these measurements, units, and notes against each item would be greatly appreciated!



Well, it all depends on how you plan on using those values.

If you just need to be able to display them, then you can store them
exactly the way they should be displayed.   But I'm guessing you may
also want to search or filter by them, in which case you have to
figure out how the searches would be querying and store values
(presumably normalized somehow to search across the whole collection)
in a way that you can query against them.



I would have a drop down menu with each of the product categories, and once one is selected, I would show a capacity range to filter, and once that is selected, I would display all the individual products for that capacity chosen. 

I would also need an easy way to convert these measurements as well as unit of measurement to the metric system for use in other countries.  

Since I'm new to MongoDB, I'm just not sure how to cleanly separate and store the measurement and it's corresponding unit.  



Would it be ok to change the size field to also include the attributes of the size?

Something like:

{
     "category" : "547295b360557a18b87c4f2f",
     "category_id_old" : "2",
     "category_grp" : "H0004",
     "old_item_id" : "6",
     "model_number" : "Brick Basket",
     "capacity" : "400 lbs.",
     "weight" : "60 lbs.",
     "size" : {"length:"30\", "width":"20\", "height":"12\""}
}

{
     "category" : "547295b760557a18b87c4f83",
     "category_id_old" : "75",
     "category_grp" : "H00030",
     "old_item_id" : "1727",
     "model_number" : "Eye-to-Eye",
     "capacity" : "5.6",
     "size" : {"diameter":" 3/4\"", "length":"19\' 1\"" }
}



That would be perfect, and I can certainly do that...the only other piece missing would be how to get the units of measurement stored separately from the values.



Too bad you don't use the metric system. :) 

Maybe you could just keep everything in inches? If a measurement is over 12 inches, reformat the number of inches stored to show feet? You might need to also use decimal places and not fractions in the data and convert them to fractions later. Looking around the Inet though, that looks like not the easiest of problems to solve.


댓글 없음:

댓글 쓰기