Mongo - Ignore property from being persisted

JavaMongodbSpring DataSpring Data-Document

Java Problem Overview


I have a standard POJO that has a set of properties in it. The POJO has been annotated as a @Document, so as to be persisted in MongoDB as a Document.

How (annotation??) can I ignore/avoid one of the properties in the POJO from being persisted?

Java Solutions


Solution 1 - Java

Solution 2 - Java

In case you are looking for the actual package like I was, this one will work:

import org.springframework.data.annotation.Transient;

Which is from the Spring framework API documentation.

But this one, which is a JPA annotation, will not work for MongoDB:

import javax.persistence.Transient;

Which is part of the Java Persistence API.

Solution 3 - Java

use @Transient be aware that you use the below package

import org.springframework.data.annotation.Transient;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSaketView Question on Stackoverflow
Solution 1 - JavaSaketView Answer on Stackoverflow
Solution 2 - JavaJeachView Answer on Stackoverflow
Solution 3 - JavaPravin BansalView Answer on Stackoverflow