All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scripts.1.9.0.3-upgrade-groups-in-events-payload.js Maven / Gradle / Ivy

There is a newer version: 4.5.2
Show newest version
print("\n\nConvert group to groups in events payload");
db.events.find().forEach(
  function (event) {
    if (event.payload && event.payload.indexOf("group\"") > 0) {
      var payloadAsJson = JSON.parse(event.payload);
      print(" - event id: " + event._id);
      print("         payload.group: " + payloadAsJson.group);
      payloadAsJson.groups = [payloadAsJson.group];
      delete payloadAsJson.group;
      print("         payload.groups: " + payloadAsJson.groups);
      event.payload = JSON.stringify(payloadAsJson);
      print(event.payload);
      db.events.updateOne(
        {
          _id: event._id
        },
        {
          $set: {
            payload: event.payload
          }
        },
        {
          upsert :true
        }
      );
      print('   ...... done. \n');
    }
  }
);




© 2015 - 2024 Weber Informatics LLC | Privacy Policy