Revision 633136333139 () - Diff

Link to this snippet: https://friendpaste.com/33QacbNL5nyGcARNN1TCdk
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
_id: "AssemblyA",
type: "Assembly"
}

Then you might also have:

{
_id: "ObjectA",
"type" : "part"
"what": "gadget",
usedIn: [
"AssemblyA",
"AssemblyB"
]
}
{
_id:"ObjectB",
"what":"widget",
"usedIn": [
"AssemblyA",
"AssembyC"
]
}
etc.

and
{
_id:"toolA",
"type": "tool"
"what":"screwdriver",
"usedIn":[
"AssemblyA"
]
}
etc.

Then, in your map function, (this is pseudocode, I didn't actually test it!)

if (type == "Assembly") { emit ([doc._id,'assembly',nil],null); }
if (type == "tool" || type == "part") {
forEach (asm in doc.usedIn) {
emit([asm,doc.type,0],null);
}
}

That will get you
['AssemblyA','assembly',nil]
['AssemblyA','part',0]
['AssemblyA','part',0]
['AssemblyA','tool',0]

If you do a query on startkey=['AssemblyA']&endkey['AssemblyA',{}]

If you use "include_docs=true" - you will get the entire doc back when you query the view.