Pergunta

I have the following query:

view.reduce.group_level(5).keys

which returns:

[["1f9c79a33f399a7937d880c5f31e8dbc", 2011, 12, 29, 13], ["1f9c79a33f399a7937d880c5f31e8dbc", 2011, 12, 29, 14], ["c38332ffc275b6c70bcf06ffc39ddbdd", 2011, 12, 29, 13], ["c38332ffc275b6c70bcf06ffc39ddbdd", 2011, 12, 29, 14]]

The first key is an id and the other keys are year, month, day, hour

I would like all the rows between 2010 and 2013. So I want to ignore the first key.

The problem is that i need to set the first parameter to get the results but i want to get all the results for all the keys.

for example: view.reduce.group_level(5).startkey(["every_possible_key", 2010]).endkey(['every_possible_key", 2013, {}])

If i leave the first key blank than i get nothing. If i give it "\u9999" than i get everything and it ignores the 2nd key.

Somebody knows what I am doing wrong?

Thanks a lot.

map:

function(d) {
    if (d['type'] == 'State' && d['driver_id'] && d['name'] && d['created_at']) {
      var dt = new Date(d.created_at);
      emit([d.driver_id, dt.getFullYear(), dt.getMonth() + 1, dt.getDate(), dt.getHours()], d.name);
    }
  }

reduce:

function(k,v,r) {
    var result = {
      'hire': 0, 'hired': 0, 'arrived': 0, 'pick up': 0, 'drop off': 0,
      'missed': 0, 'rider cancel': 0, 'driver cancel': 0, 'no show': 0,
      'avail': 0, 'unavail': 0, 'other': 0
    };
    if (r) {
      var row = null;
      for (i in v) {
        row = v[i];
        for (j in row) {
          result[j] += row[j];
        }
      }
    } else {
      for (i in v) {
        if (result[v[i]] != null) {
          result[v[i]] += 1;
        } else {
          result['other'] += 1;
        }
      }
    }

    return result;
  }
Foi útil?

Solução

What you're "doing wrong" is to use a key you don't need in your query as the first key of your view.

If you need it for another query, create another view.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top