Abhishek bhutra Abhishek bhutra - 1 month ago 12
Java Question

Update an existing collection in MongoDB using Java-Hadoop connector

Is it possible to update existing MongoDB collection with new data. I am using hadoop job to read write data to Mongo. Required scenario is :-
Say first collection in Mongo is

{
"_id" : 1,
"value" : "aaa"
"value2" : null
}


after reading data from Mongo and processing data, MongoDB should contain

{
"_id" : 1,
"value" : "aaa"
"value2" : "bbb"
}


If possible, please provide some dummy code.

Answer

I have done it by extending org.apache.hadoop.mapreduce.RecordWriter and overriding write method of this class.