couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Goodall <matt.good...@gmail.com>
Subject Re: Linking of Documents / Attachments
Date Thu, 13 May 2010 11:35:30 GMT
On 13 May 2010 12:09, c.Kleinhuis <ck@digitalgott.de> wrote:
> thank you for your answer
>>>
>>> i just decided to use couchdb in favor of hibernate/spring ... my name is
>>> christian kleinhuis
>>>
>>> and i have some general questions:
>>>
>>> 1. How is linking of documents solved ?      i would like to have
>>> something
>>> like a root node ( Project )
>>>  and i would like to associate nodes ( tasks ) to this root node,
>>>  what is the way to do it with couchdb ?
>>>  do i use the "_id" of the projekt in my task document, or do i
>>>  add the tasks as fields in the project ? but thus i couldnt edit a
>>> single
>>>  task hence it hasnt an id ...
>>>
>>
>> It really depends on the application, but a reasonable rule of thumb
>> is to store things that tend to get edited on their own in separate
>> documents. Certainly, In terms of projects and tasks I would expect a
>> project document and lots of task documents. However, something like a
>> person and his addresses almost certainly makes more sense in a single
>> document.
>>
>
> i meant, how do i associate the tasks with a certain project, assuming that
> many projects
> can be created

Ah, I thought you were just trying to decide between the two solutions
you had identified ;-).

You need to include the _id of the project somewhere in each task
document. Read http://www.cmlenz.net/archives/2007/10/couchdb-joins
for a simple example of how you might "join" the project and tasks in
a single view.

Personally, I like to represent the link from task to project as an
{"_id": "project1"} object as it allows you to *optionally* include
extra, denormalised information about the project in the link object,
e.g.:

= project =
{
  "_id": "project1",
  "type": "project",
  "name": "Project #1",
  ... lots of other stuff ...
}

= task =
{
  "_id": "task1",
  "type": "task",
  "title": "Fix things",
  "project": {"_id": "project1", "title": "Project #1"},
  ... lots of other stuff ...
}

Hope that helps more now.

- Matt

>
>
>>
>>>
>>> 2. handling attachments ... are the attached files configurable in the
>>>  file system, so that a user could go in the attachments folder and see
>>>  the files directly ?!
>>>
>>
>> Attachments are stored in the database (and are replicated to other
>> databases just like documents) but there is a FUSE driver that lets
>> you map a database to the file system,
>> http://code.google.com/p/couchdb-fuse/.
>>
>
> cool, thx for pinpointing
>
>

Mime
View raw message