The problem is how: 
"2012-02-11T22:00:00"

collates within:

"2012-02-13T16:18:19.565+0000"

remember it's basically alphanumerical... so technically, it's following collation rules.

so you really need to using a startkey like:

"2012-02-11T22:00:00.000+0000"

for it to work.

Jim Klo
Senior Software Engineer
Center for Software Engineering
SRI International

On Feb 13, 2012, at 11:11 AM, Mathieu Castonguay wrote:

I tried that exact example with
?startKey=["26de9c438e5d1c0f075f2ae6ad0bcc82","2012-02-11T22:00:00"]&endkey=["26de9c438e5d1c0f075f2ae6ad0bcc82",{}]
and I still get records in the past:

{"total_rows":3,"offset":0,"rows":[
{"id":"344e921af796598bcd709ba973003c60","key":["26de9c438e5d1c0f075f2ae6ad0b39b2","2012-02-13T16:18:19.565+0000"],"value":"344e921af796598bcd709ba973003c60"},
{"id":"344e921af796598bcd709ba973001d3f","key":["26de9c438e5d1c0f075f2ae6ad0bcc82","2012-02-10T21:44:14.920+0000"],"value":"344e921af796598bcd709ba973001d3f"},
{"id":"344e921af796598bcd709ba973002c01","key":["26de9c438e5d1c0f075f2ae6ad0bcc82","2012-02-10T22:05:48.218+0000"],"value":"344e921af796598bcd709ba973002c01"}
]}


The view's map function is:

function(doc) { if(doc.userId && doc.timeScheduled)
{emit([doc.userId,doc.timeScheduled], doc._id)} }




On Mon, Feb 13, 2012 at 1:55 PM, James Klo <jim.klo@sri.com> wrote:

Not sure how you are querying, but are you doing the equivalent to this?
startkey and endkey should be expressed as JSON

curl -g '
http://localhost:5984/orders/_design/Order/_view/by_users_after_time?startkey=[
"f98ba9a518650a6c15c566fc6f00c157","2012-01-01T11:40:52.280Z"]&endkey=["userid",{}]'


*
Jim Klo
Senior Software Engineer
Center for Software Engineering
SRI International
e. jim.klo@sri.com
p. 805.542.9330 x121
m.  805.286.1350
f. 805.546.2444
*

On Feb 13, 2012, at 10:27 AM, Mathieu Castonguay wrote:

I tried reversing the keys with no luck. I still get timestamps that are in
the past (before the startKey).

On Sat, Feb 11, 2012 at 6:37 PM, James Klo <jim.klo@sri.com> wrote:

Reverse the key. [userid, time]


CouchDB is all about understanding collation. Basically views are

sorted/grouped from left to right alphanumeric. See

http://wiki.apache.org/couchdb/View_collation for the finer details as

there are more rules than the basics I mention.


so the reversal sorts the view by userid first, then date as string.

Instead of sorting by dates then userids.


You do it this way because you know the exact userid, but not the exact

date. If you knew the exact date, but not the userid, what you have

currently would be better.


- Jim



Sent from my iPad


On Feb 11, 2012, at 1:54 PM, "Mathieu Castonguay" <

mcastonguay@justlexit.com> wrote:


I have a simple document named Order structure with the fields id, name,

userId and timeScheduled.


What I would like to do is create a view where I can find the

document.idfor those who's userId is some value and timeScheduledis

after a given date.


My view:


"by_users_after_time": {

    "map": "function(doc) { if (doc.userId && doc.timeScheduled) {

emit([doc.timeScheduled, doc.userId], doc._id); }}"

}


If I do



localhost:5984/orders/_design/Order/_view/by_users_after_time?startKey="[2012-01-01T11:40:52.280Z,f98ba9a518650a6c15c566fc6f00c157]"

I get every result back. Is there a way to access key[1] to do an if

doc.userId == key[1] or something along those lines and simply emit on

the

time?


This would be the SQL equivalent of select id from Order where userId =

"f98ba9a518650a6c15c566fc6f00c157" and timeScheduled >

2012-01-01T11:40:52.280Z;


I did quite a few Google searches but I can't seem to find a good

tutorial

on working with multiple keys. It's also possible that my approach is

entirely flawed so any guidance would be appreciated.


Thank you,


Matt