Advanced day query with CouchDB -
i have problem views in couch db (all versions 1.01 - 1.31).
my data looks :
{ "_id": "9a12b7fa4b886640be06f74b814306a6", "_rev": "1-420c723f8c8f7921ead3df04bfc9ade5", "client_id": "008", "day": 1, "month": 1, "year": 2013, "comment": "cool" }
and want see transactions client has done in span of time, lets 1 month :
so map function :
function(doc) { emit([doc.client_id, doc.day,doc.month, doc.year], doc); }
so query startkey , endkey like
http://localhost:5984/test/_design/clients/_view/by_cid_day_month_year?startkey=[%22007%22,1,1,2013]&endkey=[%22007%22,32,1,2013]
but instead of getting documents january client_id = 007, records matching 007.
so there has misunderstanding. wrong query ? how should ?
my thinking see logs specific date, or 1st jan 6th jan.
i have tried make keys day, month , year strings, result same, or weird, in above example, find record in september (9) if go april f.ex. records.
i don't understand this. should quite straight forward.
since match goes start end , stops @ first chance, you'll want emit significant search criteria first. in original query emit date before month lead date matching no matter month or year is.
if instead;
emit([doc.client_id, doc.year, doc.month, doc.day], doc);
the comparison first check year, month , last date, mean do.
as side note, match date, seem remember simplify search to;
...by_cid_year_month_day?startkey=[%22007%22,2013,1]&endkey=[%22007%22,2013,1,{}]
...since leaving last element out makes array sort before array longer (any date), , {}
sort after date. searching entire 2013 in same way be;
...by_cid_year_month_day?startkey=[%22007%22,2013]&endkey=[%22007%22,2013, {}]
Comments
Post a Comment