couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Warner Onstine <warn...@gmail.com>
Subject Re: best way to map this?
Date Thu, 09 Jul 2009 15:30:23 GMT
Here's my finalized view which I worked out (I believe it's going to
give me what I want).

{"_id":"_design/projects",
"_rev":"1-1917439739",
"language":"javascript",
"views":{"project_users":
     {"map":"function(doc) {\n
if(doc.type == \"project\")
     {\n\temit([doc._id, 0], doc);\n  }
else if (doc.type == \"user\")
{\n\tfor (var i in doc.projects)
{\n\t\temit([doc.projects[i].project_id, 1,doc._id], doc);\n\t}\n  }\n}"}}}

Let me know if you see any issues. Still curious about the joining,
whether or not I should stick with the current schema or use a
separate join document to do this.

-warner

On Wed, Jul 8, 2009 at 5:12 PM, Nicholas Orr<nicholas.orr@zxgen.net> wrote:
> One thing you'd need to do is
> for(project in doc.projects) {
>
> }
>
> right now looking at what your doing your asking for the projectid property
> of an array, which isn't what you want...
>
> I don't know about the other stuff, this is one thing I noticed.
>
> Nick
>
> On Thu, Jul 9, 2009 at 5:29 AM, Warner Onstine <warnero@gmail.com> wrote:
>
>> Hi all, I'm fairly new to CouchDB and have been reading through the
>> wiki and different articles online relating to this.
>>
>> I have two documents:
>> - Project
>> - User
>>
>> A project will have many users, and a user can belong to more than one
>> project. Initially I set it up like this:
>> Project
>> - id = "project_[name]" (where name is below)
>> - name = [name]
>> - type = "project"
>> etc.
>>
>> User
>> - id = "[User's name]"
>> - type = "user"
>> - projects = [{"project_id" = "[a specific project]", "role" =
>> "developer" (or something else)}, ...(other projects)]
>>
>> I then created a collation view (which I'm still playing with, having
>> an issue with the multiple projects part for a developer):
>> function(doc) {
>>  if(doc.type == "project") {
>>        emit([doc._id, 0], doc);
>>  } else if (doc.type == "user") {
>>        emit([doc.projects.project_id, 1], doc);
>>  }
>> }
>>
>> I've been looking at creating another document called project_users
>> (rather a new type) that I can join on, but then read the entity
>> relationship doc and it says it will require multiple queries to get
>> all the data for this type of join.
>>
>> There does exist the possibility that a user will be updating their
>> info while someone else is attempting to add them to a project (thus
>> creating a conflict).
>>
>> Looking for others thoughts on this. Thanks!
>>
>> -warner
>>
>

Mime
View raw message