javascript - complex startkey/endkey query concerning PouchDB not returning expected result -


i have created index called session_indexes/by_lastmodifieddate_status in pouchdb emit both timestamp string, indicates status.

here array keys emitted when map function run 6 documents in database:

[1404446400000, 'suspended'] [1409630400000, 'open'] [1413777600000, 'open'] [1423976400000, 'closed'] [1425704400000, 'open'] [1430193600000, 'open'] 

now, want query index using startkey , endkey. providing following:

startkey: [1422766800000, 'closed'] endkey: [1427688000000, 'closed'] 

this means want find of documents have date between these 2 timestamps , have closed status.

however, pouchdb seems return results match dates - it's returning 2 results (the other 1 being [1425704400000, 'open']).

the map function using follows. know looks strange - being generated code. not written human. still emits correct keys fine:

function(document) {   if(document._id.startswith('session')) {     var keys = [];      if(document.lastmodifieddate) {       keys.push(document.lastmodifieddate);     }      if(document.status) {       keys.push(document.status.text.touppercase());     }      emit(keys, null);   } } 

the query follows:

return database.instance().query('session_indexes/by_lastmodifieddate_status', {     startkey: [1422766800000, 'closed'],     endkey: [1427688000000, 'closed'],     include_docs: true }).then(function(result) {     return _(result.rows).map(function(row) {         return session.fromdocument(row.doc, new session());     }); }); 

edit: appear if reverse order , put status first, query works expected. can ask why? , how can fix that?

i'd appreciate can provide me. thanks!

it works way because of couchdb collation ordering. e.g. numbers+letters, you'd have:

[1, a] [1, b] [2, a] [2, b]

etc.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -