| a | b | |
|---|
| 0 | + | { |
|---|
| 0 | + | _id: "AssemblyA", |
|---|
| 0 | + | type: "Assembly" |
|---|
| 0 | + | } |
|---|
| 0 | + | |
|---|
| 0 | + | Then you might also have: |
|---|
| 0 | + | |
|---|
| 0 | + | { |
|---|
| 0 | + | _id: "ObjectA", |
|---|
| 0 | + | "type" : "part" |
|---|
| 0 | + | "what": "gadget", |
|---|
| 0 | + | usedIn: [ |
|---|
| 0 | + | "AssemblyA", |
|---|
| 0 | + | "AssemblyB" |
|---|
| 0 | + | ] |
|---|
| 0 | + | } |
|---|
| 0 | + | { |
|---|
| 0 | + | _id:"ObjectB", |
|---|
| 0 | + | "what":"widget", |
|---|
| 0 | + | "usedIn": [ |
|---|
| 0 | + | "AssemblyA", |
|---|
| 0 | + | "AssembyC" |
|---|
| 0 | + | ] |
|---|
| 0 | + | } |
|---|
| 0 | + | etc. |
|---|
| 0 | + | |
|---|
| 0 | + | and |
|---|
| 0 | + | { |
|---|
| 0 | + | _id:"toolA", |
|---|
| 0 | + | "type": "tool" |
|---|
| 0 | + | "what":"screwdriver", |
|---|
| 0 | + | "usedIn":[ |
|---|
| 0 | + | "AssemblyA" |
|---|
| 0 | + | ] |
|---|
| 0 | + | } |
|---|
| 0 | + | etc. |
|---|
| 0 | + | |
|---|
| 0 | + | Then, in your map function, (this is pseudocode, I didn't actually test it!) |
|---|
| 0 | + | |
|---|
| 0 | + | if (type == "Assembly") { emit ([doc._id,'assembly',nil],null); } |
|---|
| 0 | + | if (type == "tool" || type == "part") { |
|---|
| 0 | + | forEach (asm in doc.usedIn) { |
|---|
| 0 | + | emit([asm,doc.type,0],null); |
|---|
| 0 | + | } |
|---|
| 0 | + | } |
|---|
| 0 | + | |
|---|
| 0 | + | That will get you |
|---|
| 0 | + | ['AssemblyA','assembly',nil] |
|---|
| 0 | + | ['ObjectA','part',0] |
|---|
| 0 | + | ['ObjectB','part',0] |
|---|
| 0 | + | ['ToolA','tool',0] |
|---|
| 0 | + | |
|---|
| 0 | + | If you do a query on startkey=['AssemblyA']&endkey['AssemblyA',{}] |
|---|
| ... | |
|---|