- Spring Data Tutorial - Home
- Spring Data Apache Solr
- Overview
- Prerequisites
- Introduction
- What is Apache Solr?
- Getting Started
- Querying
- Features
- Conclusion
- Spring Data Cassandra
- Overview
- Prerequisites
- Introduction
- What is Cassandra?
- Getting Started
- Annotation AllowFiltering with Query Methods
- Partition and Clustering
- Coding hands-on on Partitioning and Clustering
- Features
- Conclusion
- Spring Data Couchbase
- Overview
- Prerequisites
- Introduction
- What is Couchbase?
- Getting Started
- Views
- CouchbaseTemplate
- Hands-on using CouchbaseTemplate
- Features
- Conclusion
- Spring Data Elasticsearch
- Overview
- Prerequisites
- Introduction
- What is ElasticSearch?
- Getting Started
- Querying
- Configuring ElasticsearchOperations bean
- Features
- Conclusion
- Spring Data JDBC
- Introduction
- Need of Spring Data JDBC
- Features
- Domain-Driven Design
- Prerequisites
- Getting Started
- Conclusion
- Spring Data JPA
- Background
- Introduction
- Prerequisites
- Getting Started
- Features
- Conclusion
- Spring Data MongoDB
- Overview
- Prerequisites
- Introduction
- What is MongoDB?
- Getting Started
- Query Methods
- Annotations
- Exposing REST end points
- Relationship
- Conclusion
- Spring Data Redis
- Overview
- Prerequisites
- Introduction
- What is Redis?
- Redis Java Clients
- Getting Started
- Features
- Conclusion
- Spring Data REST
- Background
- Introduction to Spring Data REST
- Prerequisites
- Getting Started
- Features
- Conclusion
- Spring Data Tutorial Useful Resources
- Spring Data Tutorial - Quick Guide
- Spring Data Tutorial - Useful Resources
- Spring Data Tutorial - Discussion
Spring Data MongoDB - Annotations
Spring Data MongoDB uses various annotations, lets discuss them in details
Indexes related Annotations
This type of annotation talks about indexing the fields
@Indexed
We have used this annotation above in our Customer document,
@CompoundIndexes
Spring Data MongoDB also supports compound indexes. It s used at Documents level to hold references to multiple fields using single index.
@Document
@CompoundIndexes({ @CompoundIndex(name = "name_salary", def = "{'name.id':1
, 'salary':1}") })
public class Customer {
}
In the above code we have created the compound index with name and salary fields.
Common Annotations
@Transient
As we can guess, The fields which are annotated as @Transient are not part of persistence and they are excluded from being pushed into the database. For instance
public class Customer {
@Transient
private String gender;
}
The gender will not be persisted into the database.
@Field
It is used to give a name to the field in the JSON document, We can treat this as the name attribute of @Column annotation of JPA. If we want a JSON document field to be saved other than our java field name, then we use this annotation, For Instance.
@Field("dob")
private Date dateOfBirth;
Here, our Java attribute is dateOfBirth but in the database it will be dob.