|
39 | 39 | import org.springframework.data.mongodb.core.query.Query;
|
40 | 40 | import org.springframework.data.mongodb.core.query.Update;
|
41 | 41 |
|
| 42 | +import java.time.Instant; |
42 | 43 | import java.util.Set;
|
43 | 44 |
|
44 | 45 | import static org.lowcoder.domain.util.QueryDslUtils.fieldName;
|
@@ -246,7 +247,31 @@ public void processDocument(Document document) {
|
246 | 247 | });
|
247 | 248 | }
|
248 | 249 |
|
249 |
| - @ChangeSet(order = "024", id = "add-gid-indexes-unique", author = "") |
| 250 | + @ChangeSet(order = "024", id = "fill-create-at", author = "") |
| 251 | + public void fillCreateAt(MongockTemplate mongoTemplate) { |
| 252 | + // Create a query to match all documents |
| 253 | + Query query = new Query(); |
| 254 | + |
| 255 | + // Use a DocumentCallbackHandler to iterate through each document |
| 256 | + mongoTemplate.executeQuery(query, "folder", new DocumentCallbackHandler() { |
| 257 | + @Override |
| 258 | + public void processDocument(Document document) { |
| 259 | + Object object = document.get("createdAt"); |
| 260 | + if (object != null) return; |
| 261 | + // Create an update object to add the 'gid' field |
| 262 | + Update update = new Update(); |
| 263 | + update.set("createdAt", Instant.now()); |
| 264 | + |
| 265 | + // Create a query to match the current document by its _id |
| 266 | + Query idQuery = new Query(Criteria.where("_id").is(document.getObjectId("_id"))); |
| 267 | + |
| 268 | + // Update the document with the new 'gid' field |
| 269 | + mongoTemplate.updateFirst(idQuery, update, "folder"); |
| 270 | + } |
| 271 | + }); |
| 272 | + } |
| 273 | + |
| 274 | + @ChangeSet(order = "025", id = "add-gid-indexes-unique", author = "") |
250 | 275 | public void addGidIndexesUnique(MongockTemplate mongoTemplate) {
|
251 | 276 | // collections to add gid
|
252 | 277 | String[] collectionNames = {"group", "organization"};
|
|
0 commit comments