couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Borja Martín <bor...@dagi3d.net>
Subject sorting documents using multiple keys
Date Thu, 24 Dec 2009 00:47:33 GMT
Hi,
I'm pretty new to couchdb and I'm not quite sure if this can be done. Is
there any way to sort the retrieved documents by a certain field when I
select them using multiple keys?
I have these documents for example:
{
  _id : "a",
  tags : ["foo"],
  created_at : "20091201"
},

{
  _id : "b",
  tags  : ["bar"],
  created_at : "20091231"
},

{
  _id : "c",
  tags  : ["foo", "bar"],
  created_at : "20091215"
},


Then, I create a view to store the documents for each tag:

function(doc) {
    for(var idx in doc.tags) {
      emit(doc.tags[idx], doc);
    }
  }

and eventually I can make a POST request using the keys parameter in order
the retrieve all the documents that have one or more of the given tags.
The problem is that I don't know how to sort the result by the field
created_at and I can't use it in the emit function within the key as I will
not know the value for it (and the documents can different values for it)

Any idea how to achieve this?

Thanks in advance

Regards
-- 
def dagi3d(me)
 case me
   when :web then  "http://dagi3d.net"
   when :twitter then "http://twitter.com/dagi3d"
 end
end

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message