jorasmhj / db-mongo-migration

Mongo migration Library
MIT License
7 stars 2 forks source link

Add a logger #56

Open JensWinkler91 opened 8 months ago

JensWinkler91 commented 8 months ago

It would be very useful if we could log changes during up and down.

saroj-mhj commented 8 months ago

It would be very useful if we could log changes during up and down.

@JensWinkler91 what kind of logs are we talking about? Could you give an example.

JensWinkler91 commented 8 months ago

I modify documents in multiple collections.

//Modify collection 1
  db.db.collection('collection1').updateMany({}, {
    $set: {
      param1: "param1Value"
    }
  });

//Modify collection 2
  db.db.collection('collection2').updateMany({}, {
    $set: {
      param2: "param2Value"
    }
  });

I get no information what happened if the update for collection 1 failed. To solve that, you could provide a logger that can be used to track the changes during up/down.

//Modify collection 1
Logger.info("Update collection 1");

  db.db.collection('collection1').updateMany({}, {
    $set: {
      param1: "param1Value"
    }
  });

//Modify collection 2
Logger.info("Update collection 2");

  db.db.collection('collection2').updateMany({}, {
    $set: {
      param2: "param2Value"
    }
  });