0

I am trying to work out the best way to store my daat using mongodb and mongomapper.

I have category and each category can be described by many attributes so length in mm, weight in kg etc.

I want each user to be able to create their own attributes to descibe a category of products.

So forexample:

user A wants to store his category "cars" with number of wheels and length of car in mm user B wants to store his category "cars" with number of wheels and length in mm and weight in kg.

The categories are the same for everyone but attributes can be different.

Should i be storing this as category collection then each cateogry contains and array of users each containing a hash of attribute anmes and units ?

Or should i be breaking this up into multiple collections somehow ?

Or is there a better way anyone can think of ?

Is it a problem with deep nesting ?

thanks alot in advancfe for help and advice. rick

Community
  • 1
  • 1
rick moss
  • 73
  • 4
  • This is just a re-hash of your previous question: http://stackoverflow.com/questions/3097842/ and you never bothered to accept that answer. I'll leave this question to someone else. – Gates VP Jun 30 '10 at 22:29
  • Can you please elaborate on "deep nesting" - how many levels will it actually be? – nawroth Jul 01 '10 at 07:58
  • sigh ... it's now become a popularty contest to be the first to answer or to have the "best" answer. – sdot257 Jul 02 '10 at 18:20

1 Answers1

0

Lets start with the easy answer. Store the attributes as fields in the items document. This is why one uses a schema-less data store.

Now, about which witch attributes to put with which item. Short answer: Any of the ways you describe will work; all have some trade-offs in terms of efficiency.

I think your model goes like this:

  • There is a collection users
  • There are many collections of items called categories
  • each item is a member of a category
  • each user has many items
  • every item in a category has many potential attributes depending on the user
  • some users will share attributes

I would have the following collections: users, *categories(e.g. cars, boats, houses, etc...), attributes.

The attributes collection would list a category(e.g. cars), and attribute of items in that category (e.g. fuel mileage), and a list of user_ids who use that attribute.

John F. Miller
  • 26,961
  • 10
  • 71
  • 121