Skip to content

Commit 4d5822c

Browse files
committed
Added key refresh
1 parent 61dc08a commit 4d5822c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

data/src/main/java/com/noahhusby/lib/data/storage/handlers/MongoStorageHandler.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public Collection<T> get() {
6969
FindIterable<Document> documents = collection.find();
7070
ArrayList<T> objects = new ArrayList<>();
7171
for (Document document : documents) {
72+
document.append(storage.getKey(), document.get("_id"));
7273
T object = StorageUtil.gson.fromJson(StorageUtil.gson.toJsonTree(document), storage.getClassType());
7374
objects.add(object);
7475
}
@@ -95,9 +96,12 @@ public void enableEventUpdates(Consumer<Exception> ec) {
9596
try {
9697
collection.watch().forEach((Consumer<? super ChangeStreamDocument<Document>>) x -> {
9798
if (x.getOperationType() == OperationType.INSERT) {
98-
storage.actions().add(StorageUtil.gson.fromJson(StorageUtil.gson.toJsonTree(x.getFullDocument()), storage.getClassType()));
99+
Document document = x.getFullDocument();
100+
document.append(storage.getKey(), document.get("_id"));
101+
storage.actions().add(StorageUtil.gson.fromJson(StorageUtil.gson.toJsonTree(document), storage.getClassType()));
99102
} else if (x.getOperationType() == OperationType.UPDATE) {
100103
Document doc = collection.find(x.getDocumentKey()).first();
104+
doc.append(storage.getKey(), doc.get("_id"));
101105
storage.actions().update(StorageUtil.gson.fromJson(doc.toJson(), storage.getClassType()));
102106
} else if (x.getOperationType() == OperationType.DELETE) {
103107
String key = x.getDocumentKey().get("_id").asString().getValue();

0 commit comments

Comments
 (0)