org.springframework.data.mongodb.core.index.CompoundIndexDefinition Java Examples

The following examples show how to use org.springframework.data.mongodb.core.index.CompoundIndexDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveAggregateMergeTest.java    From mongodb-aggregate-query-support with Apache License 2.0 6 votes vote down vote up
@Test
public void mustNotOverwriteExistingDocuments() throws JsonProcessingException {
  String employeeCollection = RandomStringUtils.randomAlphabetic(10);
  String orgArchiveColl = RandomStringUtils.randomAlphabetic(10);
  List<Employee> originalEmployees = addEmployeeDocuments(employeeCollection, EMPLOYEE_DOCS);
  MongoCollection<Document> employeeColl = mongoTemplate.getCollection(employeeCollection);
  validateCount(employeeCollection, originalEmployees.size());
  List<OrgArchiveEntry> orgArchiveEntries = addOrgArchiveEntries(orgArchiveColl, ORG_ARCHIVE_DOCS);
  MongoCollection<Document> orgArchiveCollection = mongoTemplate.getCollection(orgArchiveColl);
  validateCount(orgArchiveColl, orgArchiveEntries.size());
  Document index = Document.parse("{'fiscalYear': 1, 'dept': 1}");
  IndexDefinition def = new CompoundIndexDefinition(index).unique();
  mongoTemplate.indexOps(orgArchiveColl).ensureIndex(def).block();
  zooEmployeeRepository.updateOrgArchiveInsertOnly(employeeCollection, orgArchiveColl).block();
  validateCount(orgArchiveColl, orgArchiveEntries.size() + 2);
  Query query = new Query(Criteria.where("fiscalYear").is(2019));
  List<OrgArchiveEntry> newArchiveEntries = mongoTemplate.find(query, OrgArchiveEntry.class, orgArchiveColl)
                                                         .collectList().block();
  assertNotNull(newArchiveEntries);
  assertEquals(newArchiveEntries.size(), 2);
}
 
Example #2
Source File: JobIndexInitializer.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void createIndexOnExecutedCmd() {
    Document fields = new Document();
    fields.put("flowId", 1);
    fields.put("buildNumber", 1);

    mongoOps.indexOps(ExecutedCmd.class)
            .ensureIndex(new CompoundIndexDefinition(fields));
}
 
Example #3
Source File: JobIndexInitializer.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void createIndexOnExecutedCmd() {
    Document fields = new Document();
    fields.put("flowId", 1);
    fields.put("buildNumber", 1);

    mongoOps.indexOps(Step.class)
            .ensureIndex(new CompoundIndexDefinition(fields));
}