Example usage for com.mongodb.client.model IndexOptions IndexOptions

List of usage examples for com.mongodb.client.model IndexOptions IndexOptions

Introduction

In this page you can find the example usage for com.mongodb.client.model IndexOptions IndexOptions.

Prototype

IndexOptions

Source Link

Usage

From source file:io.gravitee.am.repository.mongodb.oauth2.MongoScopeApprovalRepository.java

License:Apache License

@PostConstruct
public void init() {
    scopeApprovalsCollection = mongoOperations.getCollection("scope_approvals", ScopeApprovalMongo.class);
    scopeApprovalsCollection.createIndex(new Document(FIELD_EXPIRES_AT, 1),
            new IndexOptions().expireAfter(0l, TimeUnit.SECONDS)).subscribe(new IndexSubscriber());
    scopeApprovalsCollection/* w  w  w .ja v  a  2s  .c  o m*/
            .createIndex(new Document(FIELD_DOMAIN, 1).append(FIELD_CLIENT_ID, 1).append(FIELD_USER_ID, 1))
            .subscribe(new IndexSubscriber());
    scopeApprovalsCollection.createIndex(new Document(FIELD_DOMAIN, 1).append(FIELD_CLIENT_ID, 1)
            .append(FIELD_USER_ID, 1).append(FIELD_SCOPE, 1)).subscribe(new IndexSubscriber());
}

From source file:io.lumeer.storage.mongodb.dao.organization.MongoCompanyContactDao.java

License:Open Source License

@Override
public void createCompanyContactRepository() {
    if (database.getCollection(COMPANY_CONTACT_COLLECTION) == null) {
        database.createCollection(COMPANY_CONTACT_COLLECTION);

        MongoCollection<Document> companyContactCollection = database.getCollection(COMPANY_CONTACT_COLLECTION);
        companyContactCollection.createIndex(Indexes.ascending(CompanyContactCodec.ORGANIZATION_ID),
                new IndexOptions().unique(true));
    }/*from  w  w  w  . j  a  v a 2 s  .  c  o  m*/
}

From source file:io.lumeer.storage.mongodb.dao.organization.MongoPaymentDao.java

License:Open Source License

@Override
public void createPaymentRepository(final Organization organization) {
    database.createCollection(databaseCollectionName(organization));

    MongoCollection<Document> groupCollection = database.getCollection(databaseCollectionName(organization));
    groupCollection.createIndex(Indexes.ascending(PaymentCodec.PAYMENT_ID), new IndexOptions().unique(true));
    groupCollection.createIndex(Indexes.descending(PaymentCodec.DATE), new IndexOptions().unique(true));
    groupCollection.createIndex(Indexes.descending(PaymentCodec.START), new IndexOptions().unique(true));
    groupCollection.createIndex(Indexes.descending(PaymentCodec.VALID_UNTIL), new IndexOptions().unique(true));
}

From source file:io.lumeer.storage.mongodb.dao.project.MongoViewDao.java

License:Open Source License

@Override
public void createViewsRepository(Project project) {
    database.createCollection(databaseCollectionName(project));

    MongoCollection<Document> projectCollection = database.getCollection(databaseCollectionName(project));
    projectCollection.createIndex(Indexes.ascending(ViewCodec.CODE), new IndexOptions().unique(true));
    projectCollection.createIndex(Indexes.ascending(ViewCodec.NAME), new IndexOptions().unique(true));
    projectCollection.createIndex(Indexes.text(ViewCodec.NAME));
}

From source file:io.lumeer.storage.mongodb.dao.system.MongoGroupDao.java

License:Open Source License

@Override
public void createGroupsRepository(Organization organization) {
    database.createCollection(databaseCollectionName(organization));

    MongoCollection<Document> groupCollection = database.getCollection(databaseCollectionName(organization));
    groupCollection.createIndex(Indexes.ascending(GroupCodec.NAME), new IndexOptions().unique(true));
}

From source file:io.lumeer.storage.mongodb.dao.system.MongoUserDao.java

License:Open Source License

public void createUsersRepository() {
    database.createCollection(databaseCollectionName());

    MongoCollection<Document> userCollection = database.getCollection(databaseCollectionName());
    userCollection.createIndex(Indexes.ascending(UserCodec.EMAIL), new IndexOptions().unique(true));
}

From source file:io.lumeer.storage.mongodb.dao.system.MongoUserLoginDao.java

License:Open Source License

@Override
public void createLoginRepository() {
    if (database.getCollection(COLLECTION_NAME) == null) {
        database.createCollection(COLLECTION_NAME);

        MongoCollection<Document> groupCollection = database.getCollection(COLLECTION_NAME);
        groupCollection.createIndex(Indexes.ascending(UserLoginEvent.USER_ID, UserLoginEvent.DATE),
                new IndexOptions().unique(true));
    }/*from  w  w w.  j a va2s. co  m*/
}

From source file:io.lumeer.storage.mongodb.MongoDbStorage.java

License:Open Source License

@Override
public void createIndex(final String collectionName, final DataDocument indexAttributes, boolean unique) {
    database.getCollection(collectionName).createIndex(MongoUtils.dataDocumentToDocument(indexAttributes),
            new IndexOptions().unique(unique));
}

From source file:io.mandrel.metrics.impl.MongoMetricsRepository.java

License:Apache License

@PostConstruct
public void init() {
    MongoDatabase database = mongoClient.getDatabase(properties.getMongoClientDatabase());

    counters = database.getCollection("counters");

    MongoUtils.checkCapped(database, "timeseries", size, maxDocuments);
    timeseries = database.getCollection("timeseries");

    List<Document> indexes = Lists.newArrayList(database.getCollection("timeseries").listIndexes());
    List<String> indexNames = indexes.stream().map(doc -> doc.getString("name")).collect(Collectors.toList());
    if (!indexNames.contains(INDEX_NAME)) {
        log.warn("Index on field time and type is missing, creating it. Exisiting indexes: {}", indexes);
        database.getCollection("timeseries").createIndex(new Document("timestamp_hour", 1).append("type", 1),
                new IndexOptions().name(INDEX_NAME).unique(true));
    }//from www  . j  a v  a 2 s  . co  m
}

From source file:io.seventyone.mongoutils.MongoServiceImplementation.java

License:Apache License

private void internalSetupIndexes(Class<?> entityClass, MongoCollection<Document> collection) {

    if (entityClass == null || collection == null) {
        return;//  w w w  .j  ava2s. c o  m
    }

    MongoIndex[] indexes = entityClass.getAnnotationsByType(MongoIndex.class);
    if (indexes != null && indexes.length > 0) {
        for (MongoIndex index : indexes) {
            Document indexDocument = new Document();
            indexDocument.put(index.key(), index.direction());

            IndexOptions options = new IndexOptions();
            options.unique(index.unique());
            options.background(index.background());
            collection.createIndex(indexDocument, options);
        }
    }
}