@@ -396,6 +396,32 @@ public void addTimeSeriesSnapshotHistory(MongockTemplate mongoTemplate, CommonCo
396
396
makeIndex ("createdAt" ));
397
397
}
398
398
399
+ @ ChangeSet (order ="027" ,id ="populate-email-in-user-connections" ,author ="Thomas" )
400
+ public void populateEmailInUserConnections (MongockTemplate mongoTemplate ,CommonConfig commonConfig ) {
401
+ Query query =new Query (Criteria .where ("connections.authId" ).is ("EMAIL" )
402
+ .and ("connections.email" ).is (null ));
403
+
404
+ // Get the collection directly and use a cursor for manual iteration
405
+ MongoCursor <Document >cursor =mongoTemplate .getCollection ("user" ).find (query .getQueryObject ()).iterator ();
406
+
407
+ while (cursor .hasNext ()) {
408
+ Document document =cursor .next ();
409
+
410
+ // Retrieve connections array
411
+ List <Document >connections = (List <Document >)document .get ("connections" );
412
+ for (Document connection :connections ) {
413
+ if ("EMAIL" .equals (connection .getString ("authId" )) && !connection .containsKey ("email" )) {
414
+ // Set the email field with the value of the name field
415
+ connection .put ("email" ,connection .getString ("name" ));
416
+ }
417
+ }
418
+
419
+ // Save the updated document back to the collection
420
+ mongoTemplate .getCollection ("user" ).replaceOne (new Document ("_id" ,document .get ("_id" )),document );
421
+ }
422
+
423
+ }
424
+
399
425
400
426
private void addGidField (MongockTemplate mongoTemplate ,String collectionName ) {
401
427
// Create a query to match all documents