mongodb - best practice for nested category in Mongo and Meteor -


i want handle nested category in mongo , meteor framework several ads. example this:

ads object have category field this:

maincategory_1 > subcategory_1.1 > subcategory_1.1.1 > subcategory_1.1.1.1 > { ad_1 here }                > subcategory_1.2 > subcategory_1.2.1                > subcategory_1.3   maincategory_2 > subcategory_2.1 > subcategory_2.1.1 > subcategory_2.1.1.1                 > subcategory_2.2 > subcategory_2.2.1                > subcategory_2.3  

for example ad_1 object belongs subcategory_1.1.1.1

and want access ad_1 queries this:

all maincategory_1 all subcategory_1.1 all subcategory_1.1.1 all subcategory_1.1.1.1 , all subcategory3

i have 2 approaches:

  1. store cat_id each object , merge result on multiple query.
  2. store category string of path , query on string field. this answer.

i want know 1 better??

do know other approach better performance , simplicity??

it highly depends on relationship between objects (i.e. ratio of number of objects on each side of relationship, , frequency of updates) depends on application , requirements.

a resource @ (which might take 'best practice') blog mongodb denormalization:

http://blog.mongodb.org/post/87200945828/6-rules-of-thumb-for-mongodb-schema-design-part-1

http://blog.mongodb.org/post/87892923503/6-rules-of-thumb-for-mongodb-schema-design-part-2

http://blog.mongodb.org/post/88473035333/6-rules-of-thumb-for-mongodb-schema-design-part-3

in short, because it's wide subject: we're talking n-n relationship, , depends on ratio of n's

if objects immutable, it's recommended nest them in object since won't have deal updates , search made trivial.

if objects not immutable, have weight cost of updates versus cost of searching through collection id search through other collection objects associated that/those ids.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -