Pergunta

My stored documents in a collection are in the format:

    {
        "a": {
            ...

            "b": {
                "c": cc,
                "d": dd,
                "e": ee,
                "f": ff
            }
        }

    }

I want to get fields "d" and "e" from all documents in the collection where count(c) > 1.

How can this be done efficiently?

Foi útil?

Solução

Arrived at a map-reduce solution for the problem:

My functions look like this now:

m = function() {
    emit(this.a.b.c, { data: [[this.a.b.d, this.a.b.e]] });
}

r = function(key, values) {
    var result = [];
    values.forEach(function(V) {
        Array.prototype.push.apply(result, V.data);
    });
    return {data: result};
}

db.coll.mapReduce(m, r, {out: {replace: "data"}})

Works out great for this purpose :)

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