Supported Libraries
Supported Operations
For Storing the data | Insert Operation APIs Repository APIs - org.springframework.data.repository.CrudRepository.save
- org.springframework.data.repository.CrudRepository.saveAll
- org.springframework.data.repository.ReactiveCrudRepository.save
- org.springframework.data.repository.ReactiveCrudRepository.saveAll
- org.springframework.data.repository.MongoRepository.insert
- org.springframework.data.repository.MongoRepository.save
- org.springframework.data.repository.MongoRepository.saveAll
- org.springframework.data.repository.ReactiveMongoRepository.saveAll
- org.springframework.data.repository.MongoRepository.save
- org.springframework.data.repository.ReactiveMongoRepository.insert
Template and operation APIs - org.springframework.data.mongodb.core.MongoTemplate.insert
- org.springframework.data.mongodb.core.MongoTemplate.insertAll
- org.springframework.data.mongodb.core.MongoTemplate.save
- org.springframework.data.mongodb.core.MongoTemplate.upsert
- org.springframework.data.mongodb.core.BulkOperations.upsert
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.insert
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.insertAll
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.save
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.upsert
- org.springframework.data.mongodb.core.MongoOperations.insert
- org.springframework.data.mongodb.core.MongoOperations.insertAll
- org.springframework.data.mongodb.core.MongoOperations.save
- org.springframework.data.mongodb.core.ReactiveMongoOperations.insert
- org.springframework.data.mongodb.core.ReactiveMongoOperations.insertAll
- org.springframework.data.mongodb.core.ReactiveMongoOperations.upsert
|
---|
For Fetching the data | |
---|
For Removing the data | Delete Operation APIs Repository APIs - org.springframework.data.repository.CrudRepository.deleteAll
- org.springframework.data.repository.CrudRepository.deleteById
- org.springframework.data.repository.CrudRepository.delete
- org.springframework.data.repository.ReactiveCrudRepository.deleteAll
- org.springframework.data.repository.ReactiveCrudRepository.deleteById
- org.springframework.data.repository.ReactiveCrudRepository.delete
- org.springframework.data.repository.ReactiveMongoRepository.deleteAll
- org.springframework.data.repository.ReactiveMongoRepository.deleteById
- org.springframework.data.repository.ReactiveMongoRepository.delete
- org.springframework.data.repository.MongoRepository.delete
- org.springframework.data.repository.MongoRepository.deleteAll
- org.springframework.data.repository.MongoRepository.deleteById
Template and Operation APIs - org.springframework.data.mongodb.core.MongoTemplate.findAndRemove
- org.springframework.data.mongodb.core.MongoTemplate.findAllAndRemove
- org.springframework.data.mongodb.core.MongoTemplate.dropCollection
- org.springframework.data.mongodb.core.BulkOperations.remove
- org.springframework.data.mongodb.core.MongoTemplate.remove
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.remove
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.findAndRemove
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.findAllAndRemove
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.dropCollection
- org.springframework.data.mongodb.core.ReactiveBulkOperations.remove
- org.springframework.data.mongodb.core.MongoOperations.dropCollection
- org.springframework.data.mongodb.core.MongoOperations.findAndRemove
- org.springframework.data.mongodb.core.MongoOperations.findAllAndRemove
- org.springframework.data.mongodb.core.MongoOperations.remove
- org.springframework.data.mongodb.core.ReactiveMongoOperations.dropCollection
- org.springframework.data.mongodb.core.ReactiveMongoOperations.findAndRemove
- org.springframework.data.mongodb.core.ReactiveMongoOperations.findAllAndRemove
- org.springframework.data.mongodb.core.ReactiveMongoOperations.remove
|
---|
For Updating the data | Update Operation APIs Template and Operation APIs - org.springframework.data.mongodb.core.MongoTemplate.upsert
- org.springframework.data.mongodb.core.MongoTemplate.update
- org.springframework.data.mongodb.core.MongoTemplate.updateFirst
- org.springframework.data.mongodb.core.MongoTemplate.updateMulti
- org.springframework.data.mongodb.core.MongoTemplate.findAndModify
- org.springframework.data.mongodb.core.MongoTemplate.findAndReplace
- org.springframework.data.mongodb.core.BulkOperations.updateOne
- org.springframework.data.mongodb.core.BulkOperations.updateMulti
- org.springframework.data.mongodb.core.BulkOperations.upsert
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.upsert
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.update
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.updateFirst
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.updateMulti
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.findAndModify
- org.springframework.data.mongodb.core.ReactiveMongoTemplate.findAndReplace
- org.springframework.data.mongodb.core.ReactiveBulkOperations.updateOne
- org.springframework.data.mongodb.core.ReactiveBulkOperations.updateMulti
- org.springframework.data.mongodb.core.ReactiveBulkOperations.upsert
- org.springframework.data.mongodb.core.MongoOperations.findAndModify
- org.springframework.data.mongodb.core.MongoOperations.findAndReplace
- org.springframework.data.mongodb.core.MongoOperations.upsert
- org.springframework.data.mongodb.core.MongoOperations.updateFirst
- org.springframework.data.mongodb.core.MongoOperations.updateMulti
- org.springframework.data.mongodb.core.ReactiveMongoOperations.findAndModify
- org.springframework.data.mongodb.core.ReactiveMongoOperations.findAndReplace
- org.springframework.data.mongodb.core.ReactiveMongoOperations.upsert
- org.springframework.data.mongodb.core.ReactiveMongoOperations.updateFirst
- org.springframework.data.mongodb.core.ReactiveMongoOperations.updateMulti
|
---|
Objects
Icon | Description |
---|
| Java MongoDB database |
| Java MongoDB collection |
| Java unknown MongoDB database |
| Java unknown MongoDB collection |
Links
Link type | Source and destination of link | Methods supported |
---|
parentLink | Between Mongo Objects (Collection → Database → Project) |
|
useLink | Between the caller Spring Data Java Method objects and Mongo Collection Object | |
useSelectLink | Click here to expand... - find
- findAll
- findById
- findAllById
- findAll
- count
- existsById
- exists
- findAndRemove
- findAllAndRemove
- findAndReplace
- findAndModify
- findOne
- stream
- group
- geoNear
- aggregate
- aggregateStream
- aggregateAndReturn
- executeQuery
- getCollection
- findDistinct
|
useUpdateLink | - upsert
- update
- updateFirst
- updateOne
- updateMulti
- findAndModify
- findAndReplace
|
useDeleteLink | - deleteAll
- deleteById
- delete
- findAndRemove
- dropCollection
- remove
- findAllAndRemove
|
useInsertLink | - save
- saveAll
- insert
- insertAll
- upsert
|
What results can you expect
Once the analysis/snapshot generation has completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.
Creation of database objects
With application.properties
Click here to expand...
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=hc4
logging.level.org.springframework.data=debug
logging.level.=error

With Java configuration file
Click here to expand...
package com.mkyong;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
@Configuration
@EnableMongoRepositories
public class ApplicationConfig extends AbstractMongoConfiguration{
@Override
@Bean
protected String getDatabaseName() {
return "e-store";
}
@Override
protected String getMappingBasePackage() {
return "com.oreilly.springdata.mongodb";
}
@Override
@Bean
public Mongo mongo() throws Exception {
// TODO Auto-generated method stub
return new Mongo("localhost");
}
}

Insert Operation
Click here to expand...
public Product getMrepefOne () {
Product product = new Product("LN1", "London", 5.0f);
productRepository.save(product);
return productRepository.findOne("LN1");
}

Click here to expand...
@Override
public BulkWriteResult bulk(Collection<? extends T> objects) {
Assert.notNull(objects, "Objects must not be null!");
return mongoTemplate.bulkOps(bulkMode != null ? bulkMode : BulkMode.ORDERED, Product.class)
.insert(new ArrayList<>(objects)).execute();
}

Update Operation
Update Operation
public String updateAlertStatus(String alertId) {
LOGGER.debug("FanAlertsRepository.deleteAlert() with param{0}" + alertId);
Query query = new Query();
query.addCriteria(Criteria.where(AlertServiceConstants._ID_FILED).is(new ObjectId(alertId)));
FanAlerts fanAlert = mongoOperation.findOne(query, FanAlerts.class,
AlertServiceConstants.FAN_ALERTS_COLLECTION);
if (fanAlert == null) {
return AlertServiceConstants.failure;

Delete Operation
Delete Operation
public Response deleteTn(String siteId, String tn) {
DeleteResult deleteres = mongoCon.getCollection()
.deleteOne(new Document().append(DETAILSSITE_IDEN, siteId).append(DETAILS_TN, tn));
}

Select Operation
Click here to expand...
public GeoResults getProductByLocation (double longitude,double latitude,double distance){
Point p = new Point(longitude, latitude);
NearQuery nearQuery = NearQuery.near(p, Metrics.KILOMETERS).maxDistance(distance);
return mongoTemplate.geoNear(nearQuery, Product.class);
}

Query Methods
Query Method
@Query("{ 'age' : { $gt: ?0, $lt: ?1 } }")
List<User> findUsersByAgeBetween(int ageGT, int ageLT);

Limitations
- Resolution of Database and Collection is limited, "Unknown" is used when not resolved.
- Query method results in link between query method and repository collection (domain entity) and not between the actual caller method and repository collection