android - CouchDB filtering by date -


on android using couchdb couchbase lite trying replicate database use filter in order documents field name device_number have filter:

"1": "function(doc, req) {   if(doc.ismaster || doc._deleted) return false;    if( 1 == doc.device_num || 22 == doc.device_num || 25 == doc.device_num || 41 == doc.device_num ) return true;   else  return false;}",  

it works , documents devices: 1, 2 , 25 ,41.
want documents device_num = 22 , 21 , creation_date has less 60 days present day do:

 "1": "function(doc, req) {       if(doc.ismaster || doc._deleted)     return false;        if( 22 == doc.device_num && 21 == doc.device_num && (math.ceil((new date(date.now()).gettime() - new date(doc.creation_date.split('/')[2], doc.creation_date.split('/')[1] - 1, doc.creation_date.split('/')[0]).gettime()) / (1000 * 3600 * 24)) <= 60) )     return true;       else      return false;}",  

but not getting results, 0 documents, , not true because in database there documents less 60 days.

what doing wrong?

i want documents device_num = 22 , 21 , creation_date has less 60 days present day

english wording: "i want documents 21 and 22" "i'll accept document document either 21 or 22":

       if( (22 == doc.device_num || 21 == doc.device_num) && ...) 

as no document single device_num can simultaneously devices 21 , 22.

dates bit of mess around world , knows if user's in same time zone? couchdb provides some examples of considering collation factors in dates, , here example of using number type safe collation:

 // creation:  {tstamp:+new date(), device_num:22, ...}  // test  validstamp = +new date() - 1000*60*60*24*60;  if( (22 == doc.device_num || 21 == doc.device_num) && number(doc.tstamp) > validstamp)      ... 

its nice use number() in case went wrong in storage , have stored string. numbers, logically sequential without oddities of non-zero padded strings around 1980s , distant future , can later refactor using mango indexes with:

{   "tstamp": {'$gt':validstamp},   "$or": [       { "device_num": 21 },       { "device_num": 22 }   ] }   

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -