couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neville Franks <>
Subject View with key1 and key2 query
Date Thu, 09 Dec 2010 22:56:45 GMT
I am interested in a document model like that described in using 'One to Many'
using separate documents. For example:

( type: "article", id: "a1", desc: "abc1" }
( type: "article", id: "a2", desc: "abc2" }
( type: "tags", tag: "blue", articles: ["a1"] }
( type: "tags", tag: "red", articles: ["a1","a2"] }
( type: "tags", tag: "green", articles: ["a2"] }
( type: "tags", tag: "white", articles: [] }

This is a database of articles, where each article can have many tags.
The articles array holds the id's for the articles using the tag. So
far so good and this all works well.

What I'd like to do and hence my question is to query the database
1) tags = red or green. result: {[{tag: "red", ..},{tag: "green",..}]}
2) Article with tags red and green. result: {[type: "article", id:"a2"]}

These need to specified dynamically with ?key= style, not coded in the
mentions: {"keys": ["key1", "key2", ...]} and I wonder whether this
will do what I want. If not does anyone have any suggestions.

I realize I can issue separate view requests and do something like
a union on the returned results sets, however I'd much prefer to get
CouchDB to do this for me.

Best regards,
  Neville Franks,

View raw message