I was modeling the graph structure (property graph with named relations) in couchdb and would like to know what potential performance bottlenecks I would find.
I use the following principles:
- Keep documents small.
- Try to embed as little as possible.
- Record all relationships between documents as a new document (link).
It seems that all these principles contradict the philosophy of CouchDB,
With these principles, for example, tagging a person becomes three documents:
{ _id: '10', type: 'person', 'name': 'John Doe' }
{ _id: '20', type: 'tag', 'name': 'Important' }
{ _id: '30', type: 'link', from: 10, to: 20, name: 'tag' }
I also created the following views in a document _designcalled links:
{
outgoing: {
map: function(doc) {
if (doc.type == 'link') {
emit([doc.from, doc.name], {_id: doc.to});
}
}
},
incoming: {
map: function(doc) {
if (doc.type == 'link') {
emit([doc.to, doc.name], { _id: doc.from });
}
}
}
}
I can get all links in or out of a document with these URLs:
http://host/db/_design/links/_view/incoming?startkey=["10"]&endkey=["10",{}]
http://host/db/_design/links/_view/outgoing?startkey=["10"]&endkey=["10",{}]
I can even get all links by name with these URLs:
http://host/db/_design/links/_view/incoming?startkey=["10","tag"]&endkey=["10","tag",{}]
http://host/db/_design/links/_view/outgoing?startkey=["10","tag"]&endkey=["10","tag",{}]
include_docs=true , ; , . . , .
:
- . , .
- , , .
link, .- .
link . - .
- . , , .
- . , , .
- "" , , , . , ?
- , , , , ( !).
, :
- , ?
- ?
- , ?