CAST supports MongoDB via its NoSQL for Java extension. Details about how this support is provided for Java with Spring Data source code is discussed below.

Supported Libraries

Supported till version 3.2.x

Supported Operations

For Storing the data

    • 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.ReactiveMongoRepository.insert
    • 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


  • org.springframework.data.repository.CrudRepository.findAll
  • org.springframework.data.repository.CrudRepository.count
  • org.springframework.data.repository.CrudRepository.findById
  • org.springframework.data.repository.CrudRepository.findAllById
  • org.springframework.data.repository.CrudRepository.existsById
  • org.springframework.data.repository.PagingAndSortingRepository.findAll
  • org.springframework.data.repository.QueryByExampleExecutor.count
  • org.springframework.data.repository.QueryByExampleExecutor.exists
  • org.springframework.data.repository.QueryByExampleExecutor.findAll
  • org.springframework.data.repository.QueryByExampleExecutor.findOne
  • org.springframework.data.repository.ReactiveCrudRepository.findAll
  • org.springframework.data.repository.ReactiveCrudRepository.count
  • org.springframework.data.repository.ReactiveCrudRepository.findById
  • org.springframework.data.repository.ReactiveCrudRepository.findAllById
  • org.springframework.data.repository.ReactiveCrudRepository.existsById
  • org.springframework.data.repository.ReactiveQueryByExampleExecutor.count
  • org.springframework.data.repository.ReactiveQueryByExampleExecutor.exists
  • org.springframework.data.repository.ReactiveQueryByExampleExecutor.findAll
  • org.springframework.data.repository.ReactiveQueryByExampleExecutor.findOne
  • org.springframework.data.repository.ReactiveMongoRepository.findAll
  • org.springframework.data.mongodb.core.MongoTemplate.getCollection
  • org.springframework.data.mongodb.core.MongoTemplate.find
  • org.springframework.data.mongodb.core.MongoTemplate.findAll
  • org.springframework.data.mongodb.core.MongoTemplate.findAllAndRemove
  • org.springframework.data.mongodb.core.MongoTemplate.findAndModify
  • org.springframework.data.mongodb.core.MongoTemplate.findAndRemove
  • org.springframework.data.mongodb.core.MongoTemplate.findAndReplace
  • org.springframework.data.mongodb.core.MongoTemplate.findById
  • org.springframework.data.mongodb.core.MongoTemplate.findDistinct
  • org.springframework.data.mongodb.core.MongoTemplate.findOne
  • org.springframework.data.mongodb.core.MongoTemplate.exists
  • org.springframework.data.mongodb.core.MongoTemplate.count
  • org.springframework.data.mongodb.core.MongoTemplate.collectionExists
  • org.springframework.data.mongodb.core.MongoTemplate.stream
  • org.springframework.data.mongodb.core.MongoTemplate.group
  • org.springframework.data.mongodb.core.MongoTemplate.geoNear
  • org.springframework.data.mongodb.core.MongoTemplate.aggregate
  • org.springframework.data.mongodb.core.MongoTemplate.aggregateStream
  • org.springframework.data.mongodb.core.MongoTemplate.aggregateAndReturn
  • org.springframework.data.mongodb.core.MongoTemplate.executeQuery
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.getCollection
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.find
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.findAll
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.findAllAndRemove
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.findAndModify
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.findAndRemove
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.findAndReplace
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.findById
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.findDistinct
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.findOne
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.exists
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.count
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.collectionExists
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.stream
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.group
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.geoNear
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.aggregate
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.aggregateStream
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.aggregateAndReturn
  • org.springframework.data.mongodb.core.ReactiveMongoTemplate.executeQuery
  • org.springframework.data.mongodb.core.MongoOperations.aggregate
  • org.springframework.data.mongodb.core.MongoOperations.aggregateStream
  • org.springframework.data.mongodb.core.MongoOperations.aggregateAndReturn
  • org.springframework.data.mongodb.core.MongoOperations.collectionExists
  • org.springframework.data.mongodb.core.MongoOperations.count
  • org.springframework.data.mongodb.core.MongoOperations.exists
  • org.springframework.data.mongodb.core.MongoOperations.find
  • org.springframework.data.mongodb.core.MongoOperations.findAll
  • org.springframework.data.mongodb.core.MongoOperations.findAllAndRemove
  • org.springframework.data.mongodb.core.MongoOperations.findAndModify
  • org.springframework.data.mongodb.core.MongoOperations.findAndRemove
  • org.springframework.data.mongodb.core.MongoOperations.findAndReplace
  • org.springframework.data.mongodb.core.MongoOperations.findById
  • org.springframework.data.mongodb.core.MongoOperations.findOne
  • org.springframework.data.mongodb.core.MongoOperations.geoNear
  • org.springframework.data.mongodb.core.MongoOperations.getCollection
  • org.springframework.data.mongodb.core.MongoOperations.group
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.aggregate
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.aggregateStream
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.aggregateAndReturn
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.collectionExists
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.count
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.exists
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.find
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.findAll
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.findAllAndRemove
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.findAndModify
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.findAndRemove
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.findAndReplace
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.findById
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.findOne
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.geoNear
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.getCollection
  • org.springframework.data.mongodb.core.ReactiveMongoOperations.group


For Removing the data


  • 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.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


  • 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

IconDescription

Java MongoDB database

Java MongoDB collection

Java unknown MongoDB database

Java unknown MongoDB collection

Links

Link typeSource and destination of linkMethods supported
parentLink

Between Mongo Objects (Collection → Database → Project)


useLinkBetween the caller Spring Data Java Method objects and Mongo Collection Object
  • mapReduce

useSelectLink


  • 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 object 

With application.properties


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


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


@Component("storeOrder")
public class StoreOCEOrder implements Processor {

	private static final Logger log = LoggerFactory.getLogger(StoreOCEOrder.class);

	@Autowired
	private OceOrderRepository repository;

	public void process(Exchange exg) throws Exception {
		repository.save(oceResponse);
	}
}



public String saveAlerts(List<FanAlerts> documentsToSave) {
		LOGGER.debug("FanAlertsRepository.saveAlerts()");
		mongoOperation.insert(documentsToSave, FanAlerts.class);
		return AlertServiceConstants.ALERT_CREATED_MESSAGE;
	}

Update Operation


public Response deleteCSPProfileLocation(CSPProfileDeleteLocationRequest req) {
	UpdateResult result = collection.getExposedDocCollection().updateOne(filter, cond);
}


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


public void elkFailureReprocess() {
	Document getTnDoc = (Document) mongoCon.getCollection("TN").find(eq("details.tn", id)).first();
}

Query Methods 


public interface OrderCountersRepository extends MongoRepository<Counters, String> {
	@Query(value = "{'_id':?0}")
	public Counters findById(String orderId);
}

Evolution

Limitations