NoSql RavenDb data design - maximum maps produced issue -
we using ravendb our nosql datastore. store huge amount of data needs high performance on queries.
our current relational model translated document structure, use non relevant class names because cannot disclose real business case:
- company
has it's own properties , contains list of stores (around 50)
- store
has it's own properties , contains list of product (around 150)
- product
has it's own properties
we have stored json:
{ "id": 1, "companyname": "first company", "location": "not far", "stores": [ { "id": 125, "companyid": 1, "storename": "sweets", "products": [ { "id": 1289, "storeid": 125, "name": "candy", "price" : 10 } ] } ] }
we want expose each sublist of document odata service.
we added index map selected level got ravendb error allowed 15 mapped outputs per document.
we alternatively store lowest level (product) , duplicate store , company data. seems bad design.
you're creating what's called fanout index , ravendb has limit number of fanouts 15 default. partly due fact fanout indexes hard optimize performance db.
in case, looks you're going store 1 document per "company" holds company stores , each store holds products. if that's case, document might rather large , migh cause concurrency problems if in document modified more 1 person @ same time.
consider storing company 1 document holds id reference each of stores
{ "id": "companies/1", "companyname": "first company", "location": "not far", "stores": [ "stores/1", "stores/2" ] }
and each store (also separate document) holds reference each product:
{ "id": "stores/1", "companyid": "companies/1", "storename": "sweets", "products": [ "products/1", "products/2" ] }
and products (also separate document) holds reference store (if product can in 1 store, looks in example):
{ "id": "products/1", "storeid": "stores/1", "name": "candy", "price" : 10 }
now can create kind of index want, products_bystore
, stores_bycompany
etc. can products_bystore_andbycompany
if decide store companyid directly on product (or use loaddocument inside products index loads store , maps stores company id, try avoid if possible).
if want return in same form json example can loaddocument on companyid , use resulttransformer
loads stores , products on server , returns everything. however, might rather "expensive" operation, based on how many stores , products company have, @ least it's server side (kind of join in sql).
don't afraid use relations in document db raven, think how usage be. can combine relation id more information store, name, if you're loading company , want list stores name. document might this:
{ "id": "companies/1", "companyname": "first company", "location": "not far", "stores": [ { "id": "stores/1", "name": "sweets" }, { "id": "stores/2", "name": "another store name" } ] }
now store name duplicated , of course have updated on company document if changed in store document.
as always, depends. hope have given @ least!
//j
Comments
Post a Comment