Skip to content

Commit

Permalink
Merge pull request #1383 from lowcoder-org/fix/byuser
Browse files Browse the repository at this point in the history
organization/byuser endpoint issue fixed
  • Loading branch information
FalkWolsky authored Dec 7, 2024
2 parents a55bd38 + 8bfb6c1 commit 1500c55
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,32 @@ public void addTimeSeriesSnapshotHistory(MongockTemplate mongoTemplate, CommonCo
makeIndex("createdAt"));
}

@ChangeSet(order = "027", id = "populate-email-in-user-connections", author = "Thomas")
public void populateEmailInUserConnections(MongockTemplate mongoTemplate, CommonConfig commonConfig) {
Query query = new Query(Criteria.where("connections.authId").is("EMAIL")
.and("connections.email").is(null));

// Get the collection directly and use a cursor for manual iteration
MongoCursor<Document> cursor = mongoTemplate.getCollection("user").find(query.getQueryObject()).iterator();

while (cursor.hasNext()) {
Document document = cursor.next();

// Retrieve connections array
List<Document> connections = (List<Document>) document.get("connections");
for (Document connection : connections) {
if ("EMAIL".equals(connection.getString("authId")) && !connection.containsKey("email")) {
// Set the email field with the value of the name field
connection.put("email", connection.getString("name"));
}
}

// Save the updated document back to the collection
mongoTemplate.getCollection("user").replaceOne(new Document("_id", document.get("_id")), document);
}

}


private void addGidField(MongockTemplate mongoTemplate, String collectionName) {
// Create a query to match all documents
Expand Down

0 comments on commit 1500c55

Please sign in to comment.