0

私はmongoに次のドキュメントを持っています:

{
        "_id" : ObjectId("501535acd729190bd62e3a58"),
        "o_orderkey" : NumberLong(1),
        "o_custkey" : {
                "$ref" : "customer",
                "$id" : ObjectId("5012e490cabc8baea9a541dd")
        },
        "o_orderstatus" : "O",
        "o_totalprice" : 173665.47,
        "o_orderdate" : ISODate("1996-01-02T02:00:00Z"),
        "o_orderpriority" : "5-LOW",
        "o_clerk" : "Clerk#000000951",
        "o_shippriority" : 0,
        "o_comment" : "blithely final dolphins solve-- blithely blithe packages nag blith",
        "o_lineitem" : [
                {
                        "_id" : ObjectId("501535abd729190bd62e38c7"),
                        "orderKey" : NumberLong(1),
                        "l_partkey" : {
                                "$ref" : "part",
                                "$id" : ObjectId("500f3a03d7292535356b839c")
                        },
                        "l_supplierkey" : {
                                "$ref" : "supplier",
                                "$id" : ObjectId("4ffed5dd125ee93ca6f3b294")
                        },
                        "l_linenumber" : 1,
                        "l_quantity" : 17,
                        "l_extendedprice" : 21168.23,
                        "l_discount" : 0.04,
                        "l_tax" : 0.02,
                        "l_returnflag" : "N"
                },
                {
                        "_id" : ObjectId("501535abd729190bd62e38c8"),
                        "orderKey" : NumberLong(1),
                        "l_partkey" : {
                                "$ref" : "part",
                                "$id" : ObjectId("500f398ed7292535356a2c54")
                        },
                        "l_supplierkey" : {
                                "$ref" : "supplier",
                                "$id" : ObjectId("4ffed5dd125ee93ca6f3b109")
                        },
                        "l_linenumber" : 2,
                        "l_quantity" : 36,
                        "l_extendedprice" : 45983.16,
                        "l_discount" : 0.09,
                        "l_tax" : 0.06,
                        "l_returnflag" : "N"
                }
        ]
}

そして、「o_shippriority」= 0および「l_linenumber」= 1の場合、「l_quantity」を合計する必要があります。これを試しました:

db.runCommand({ 
    mapreduce: "orders", 
    query: {
        o_shippriority: 0,
        "l_lineitem.l_linenumber": 1
    },
    map : function Map() {
        emit("sum",{this.o_lineitem}); 
    },
    reduce : function Reduce(key, values) {
        var sum = 0;
        for (var i = 0; i < values.length; i++) {
            var lineitem = values[i];
            for (var j=0; j<lineitem.length; j++) {
                sum += lineitem.l_quantity;
            }
        }
        return sum;
    },  
    out: 'query'
});

「SyntaxError: missing : after property id (shell):8」というメッセージが表示されて動作しません。

4

1 に答える 1