user3556304
user3556304

Reputation: 1037

Spring Data MongoDB : how to partially map domain object to MongoDB?

Let's say we have four fields in a Java domain object.

Instead of mapping all fields into the MongoDB document, are there ways to selectively map three fields to the MongoDB?

public class Person {

  @Id 
  private String id;
  private String name;

  // we don't want to map this field into MongoDB
  private String noMongoDB.

  // getters and setters
}

Upvotes: 1

Views: 396

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121507

org.springframework.data.annotation.Transient is for you.

The same premise as it is with the same annotation from JPA.

public class Person {

  @Id 
  private String id;

  private String name;

  @Transient
  private String noMongoDB.

}

Upvotes: 5

Related Questions