Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference to Raw Mongo Object #649

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/sirius/db/mongo/Mango.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ public static <E extends MongoEntity> E make(EntityDescriptor descriptor, Doc do
E result = (E) descriptor.make(Mango.class,
null,
key -> doc.getUnderlyingObject().containsKey(key) ? doc.get(key) : null);

result.setMongoDocument(doc);

if (descriptor.isVersioned()) {
result.setVersion(doc.get(VERSION).asInt(0));
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/sirius/db/mongo/MongoEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public abstract class MongoEntity extends BaseEntity<String> {
@Transient
protected int version = 0;

@Transient
protected Doc mongoDocument;

@Part
protected static Mongo mongo;

Expand Down Expand Up @@ -99,4 +102,18 @@ public int getVersion() {
public void setVersion(int version) {
this.version = version;
}

/**
* Returns the underlying {@linkplain Doc Mongo document}. Be aware that this is only available after loading the
* {@linkplain MongoEntity entity} from the database, and the document is not updated automatically.
*
* @return the underlying Mongo document
*/
public Doc getMongoDocument() {
return mongoDocument;
}

protected void setMongoDocument(Doc mongoDocument) {
this.mongoDocument = mongoDocument;
}
}