Reputation: 15752
I have the following situation:
day: {data:data,data:data}
day: {data:data,data:data}
This data should become:
week:[day,day,day..]
This is a one time job. I want to do it in the command line or Robomongo.
Upvotes: 0
Views: 570
Reputation: 48006
Since we can't see your exact document structure, I'll try to give a simple solution that should work no matter what structure your documents have.
Basically you would want to iterate over each of the documents in the source collection and generate an array of all the values.
week_array = []
db.source_col.find({}).forEach( function( doc ){
week_array.push( doc );
} );
You now have an array containing all the documents from the source_collection. All you have to do now is construct a new document and insert the array into it at the correct attribute:
var week_doc = { "week": week_array };
Now just insert it into the target collection:
db.target_col.insert( week_doc );
Upvotes: 1