incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Olivier Le Thanh Duong <oliv...@lethanh.be>
Subject Multiple keys and partial query.
Date Tue, 23 Feb 2010 00:24:44 GMT
Hello,
I am playing a bit with CouchDB and I ended up with a view with
multiple key and I find a strange behaviour while querying it so I'm
pondering if this is considered normal or if I'm doing thing the wrong
way.

I basically have a database where document are short simple messages,
each with fields sender, receiver, text and datetime. Sender and
Receiver are simple strings identifier and the datetime are array of
interger. e.g  [2009,12,6,20,5,40]
I found this format for the datetime in the O'Reilly couchdb book, I
don't know if that's the prefered format or not but it allow to
specify only part of the date in requests.

So first I wanted to get all the message from one person so I first
created a view like this :
function(doc) {
  emit(doc.sender, doc);
}
and queried it with ?inclusive_end=true&startkey="name"&endkey="name"
This works fine.

But then I wanted to have them sorted by date so I added the date to
my key and put both in an array.

function(doc) {
  emit([doc.sender, doc.date], doc);
}

Which give me keys like : ["Sender",[2009,11,16,16,34,49]]

If I do a query specifying whole key it works fine e.g
?inclusive_end=true&endkey=["Sender",[2011, 0, 0, 0,
0,0]]&startkey=["Sender",[0, 0, 0, 0, 0,0]]
But CouchDb is supposed to be able to retrieve result even when only
the start of a key is present, so for example I can query specifying
only ["Sender",[2009]] and it works.
However if I do a request with only ["Sender"] or ["Sender",[]] I
don't get any result.

So is this considered normal behaviour? Is it a bug? Is it already
fixed in a latter version ?  (The version of CouchDB I'm using is
0.10.0)
Or am I doing thing the wrong way?

Regards,
Olivier


-- 
Olivier LĂȘ Thanh Duong <olivier@lethanh.be>

Phone : +32485608639 Jabber: olethanh@gmail.com

Mime
View raw message