MongoTemplate is the central support class for Mongo database operations. It provides
MongoTemplate is the central support class for Mongo database operations. It provides
@ -54,93 +48,98 @@ Future plans are to support optional logging and/or exception throwing based on
### Easy Data Repository generation
### Easy Data Repository generation
To simplify the creation of Data Repositories a generic Repository interface and default implementation is provided. Furthermore, Spring will automatically create a Repository implementation for you that adds implementations of finder methods you specify on an interface.
To simplify the creation of data repositories a generic `Repository` interface and default implementation is provided. Furthermore, Spring will automatically create a Repository implementation for you that adds implementations of finder methods you specify on an interface.
The Repository interface is
The Repository interface is
public interface Repository<T,IDextendsSerializable> {
```java
public interface Repository<T,IDextendsSerializable> {
T save(T entity);
List<T> save(Iterable<? extends T> entities);
T save(T entity);
T findById(ID id);
List<T> save(Iterable<? extends T> entities);
boolean exists(ID id);
T findById(ID id);
List<T> findAll();
boolean exists(ID id);
Long count();
List<T> findAll();
void delete(T entity);
Long count();
void delete(Iterable<? extends T> entities);
void delete(T entity);
void deleteAll();
void delete(Iterable<? extends T> entities);
}
void deleteAll();
}
```
The MongoRepository extends Repository and will in future add more Mongo specific methods.
public interface MongoRepository<T,IDextendsSerializable> extends
The `MongoRepository` extends `Repository` and will in future add more Mongo specific methods.
Repository<T,ID> {
}
SimpleMongoRepository is the out of the box implementation of the MongoRepository you can use for basid CRUD operations.
```java
public interface MongoRepository<T,IDextendsSerializable> extends Repository<T,ID> {
}
```
To go beyond basic CRUD, extend the MongoRepository interface and supply your own finder methods that follow simple naming conventions such that they can be easily converted into queries.
`SimpleMongoRepository` is the out of the box implementation of the `MongoRepository` you can use for basid CRUD operations.
For example, given a Person class with first and last name properties, a PersonRepository interface that can query for Person by last name and when the first name matches a regular expression is shown below
To go beyond basic CRUD, extend the `MongoRepository` interface and supply your own finder methods that follow simple naming conventions such that they can be easily converted into queries.
public interface PersonRepository extends MongoRepository<Person,Long> {
For example, given a `Person` class with first and last name properties, a `PersonRepository` interface that can query for `Person` by last name and when the first name matches a regular expression is shown below
List<Person> findByLastname(String lastname);
```java
public interface PersonRepository extends MongoRepository<Person,Long> {