couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: business model / 'ER' help
Date Tue, 01 Jun 2010 05:19:47 GMT
Excellent proposal Randall, thats an awesome idea, but what if my store 
stock a 200 000 of each item - I think your idea defeats the purpose of 
storing documents a bit, dont you? I have opted to base my documents on 
each product, inside product I have a field called stores which contains 
an array of 3 stores each with a name and item count.. and see if I can 
tackle it that way. Thoughts?

Randall Leeds <>
01/06/2010 01:48 PM
Re: business model / 'ER' help

The easiest thing in my mind would be to have a document for each
inventory item that contains its name and the store where it's in
This is actually kinda nice because it lets you track individual
instances of each item, like if you wanted to order the item to be
sent from one store to another you could modify the store property.

I think you can get away with only two map functions.
Make one map that emits a key like {[item, store]: item_id}. Call it
Another map emits keys like {[store, item]: item_id}. Call it 
Then all three of your questions are simple summation ({"reduce":
"_count"}) reductions.

1. _design/inventory/_view/items_by_name?group=true&group_level=1

I think this would work for you. You might need to url encode those keys.
The startkey and endkey parameters are chosen based on the collation

Happy map(-reduc)ing!


On Mon, May 31, 2010 at 20:14,  <> wrote:
> Hi I am trying to get my head around a simple practice task, however I
> can't stop thinking about relational models as opposed to document 
> hehe
> ok so i have one couchDB database that has to contain 3 stores, each 
> has a product inventory (i.e product name, qty)
> I have to be able to:
> 1. list the total qty of each item (i.e across all stores)
> 2. list the QTY of a certain item within each store
> 3. list all items, their qty for a specific store
> ...I could smash this out in SQL in a few minutes...but cant get my head
> around doing it as would I have a document for each 
> containing product attributes(i.e p1, p2 etc)? or a document for each
> product containing store attributes(i.e P > s1-qty, s2-qty, s3-qty)?
> or (and i doubt this be true) would i have separate store docs and 
> docs and somehow link then like I would in a 'real' (:-p) database lol
> wasnt sure if these kinds of Q's were asked in here so thought id just
> give it a shot

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message