0

I am having around 1M records in a collection of the form :

{
  _id:1,
   name : 'Testing0,
   address : 'Testing Address0'
},
 {
  _id:2,
   name : 'Testing1',
   address : 'Testing Address1'
},
{
  _id:3,
   name : 'Testing2',
   address : 'Testing Address2'
}

The required format I want is as follows :

{
  _id:1,
  Employee : {
  _id:1,
   name : 'Testing0,
   address : 'Testing Address0'
}
   },
{
  _id : 2,
 Employee : {
  _id:2,
   name : 'Testing1',
   address : 'Testing Address1'
}
  } ,
{
 _id : 3,
  Employee : {
  _id:3,
   name : 'Testing2',
   address : 'Testing Address2'
}
}

and so on.......

finally got the query :

  db.test.find().forEach(
function (elem) {
    var e = elem;
    db.test.update(
        {
            _id: elem._id
        },
         {
            $set: {
              //  name: elem.firstname + ' ' + elem.lastname
                "Employee":e


            }
        }


    );
        db.test.update(
        {
            _id: elem._id
        },
         {
            $unset: {
              //  name: elem.firstname + ' ' + elem.lastname

    'name':1
           }
        }  
    );         
}
   );

Please let me know how to do this mongodb and spring-data-mongodb Regards Kris

chiku
  • 485
  • 2
  • 8
  • 23

0 Answers0