In MongoDB mapreduce, how can I flatten the values object?

前端 未结 7 2183
挽巷
挽巷 2020-12-04 22:22

I\'m trying to use MongoDB to analyse Apache log files. I\'ve created a receipts collection from the Apache access logs. Here\'s an abridged summary of what my

7条回答
  •  长情又很酷
    2020-12-04 22:43

    You can do Dan's code with a collection reference:

        function clean(collection) { 
          collection.find().forEach( function(result) {
          var value = result.value;
          delete value._id;     
          collection.update({_id: result._id}, value);     
          collection.update({_id: result.id}, {$unset: {value: 1}} ) } )};
    

提交回复
热议问题