mongoDB map/reduce minus the reduce

后端 未结 5 1803
清歌不尽
清歌不尽 2021-02-01 21:02

I have some 25k documents (4 GB in raw json) of data that I want to perform a few javascript operations on to make it more accessible to my end data consumer (R), a

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 21:41

    When using map/reduce you'll always end up with

    { "value" : {  } }
    

    In order to remove the value key you'll have to use a finalize function.

    Here's the simplest you can do to copy data from one collection to another:

    map = function() { emit(this._id, this ); }
    reduce = function(key, values) { return values[0]; }
    finalize = function(key, value) { db.collection_2.insert(value); }
    

    Then when you would run as normal:

    db.collection_1.mapReduce(map, reduce, { finalize: finalize });
    

提交回复
热议问题