modules/core/nuxeo-core-storage-mongodb/src/main/java/org/nuxeo/ecm/core/storage/mongodb/MongoDBConnection.java
/**
     * Initializes the MongoDB repository
     *
     * @param descriptor the MongoDB repository descriptor
     * @since 11.1
     */
Initializes the MongoDB repository
@param descriptor the MongoDB repository descriptor
@since 11.1
Initializes the MongoDB repository @param descriptor the MongoDB repository descriptor @since 11 . 1
protected void initRepository(MongoDBRepositoryDescriptor descriptor) {
        if (coll.countDocuments(converter.filterEq(KEY_ID, getRootId())) > 0) {
            return;
        }
        if (useCustomId) {
            coll.createIndex(Indexes.ascending(KEY_ID), new IndexOptions().unique(true));
        }
        coll.createIndex(Indexes.ascending(KEY_PARENT_ID));
        coll.createIndex(Indexes.ascending(KEY_ANCESTOR_IDS));
        coll.createIndex(Indexes.ascending(KEY_VERSION_SERIES_ID));
        coll.createIndex(Indexes.ascending(KEY_PROXY_TARGET_ID));
        coll.createIndex(Indexes.ascending(KEY_PROXY_VERSION_SERIES_ID));
        coll.createIndex(Indexes.ascending(KEY_READ_ACL));
        IndexOptions parentNameIndexOptions = new IndexOptions();
        if (descriptor != null) {
            parentNameIndexOptions.unique(Boolean.TRUE.equals(descriptor.getChildNameUniqueConstraintEnabled()));
        }
        coll.createIndex(Indexes.ascending(KEY_PARENT_ID, KEY_NAME), parentNameIndexOptions);
        coll.createIndex(Indexes.ascending(KEY_PRIMARY_TYPE));
        coll.createIndex(Indexes.ascending(KEY_LIFECYCLE_STATE));
        coll.createIndex(Indexes.ascending(KEY_IS_TRASHED));
        coll.createIndex(Indexes.ascending(KEY_RETAIN_UNTIL));
        if (!repository.isFulltextDisabled()) {
            coll.createIndex(Indexes.ascending(KEY_FULLTEXT_JOBID));
        }
        coll.createIndex(Indexes.ascending(KEY_ACP + "." + KEY_ACL + "." + KEY_ACE_USER));
        coll.createIndex(Indexes.ascending(KEY_ACP + "." + KEY_ACL + "." + KEY_ACE_STATUS));
        coll.createIndex(Indexes.descending("dc:modified"));
        coll.createIndex(Indexes.ascending("rend:renditionName"));
        coll.createIndex(Indexes.ascending("rend:sourceId"));
        coll.createIndex(Indexes.ascending("rend:sourceVersionableId"));
        coll.createIndex(Indexes.ascending("drv:subscriptions.enabled"));
        coll.createIndex(Indexes.ascending("collectionMember:collectionIds"));
        coll.createIndex(Indexes.ascending("nxtag:tags"));
        coll.createIndex(Indexes.ascending("coldstorage:beingRetrieved"));
        if (!repository.isFulltextSearchDisabled()) {
            Bson indexKeys = Indexes.compoundIndex( 
                    Indexes.text(KEY_FULLTEXT_SIMPLE), 
                    Indexes.text(KEY_FULLTEXT_BINARY) 
            );
            IndexOptions indexOptions = new IndexOptions().name(FULLTEXT_INDEX_NAME).languageOverride(LANGUAGE_FIELD);
            coll.createIndex(indexKeys, indexOptions);
        }
         create basic repository structure needed
        IdType idType = repository.getIdType();
        if (idType == IdType.sequence || idType == IdType.sequenceHexRandomized || DBSRepositoryBase.DEBUG_UUIDS) {
             create the id counter
            long counter;
            if (idType == IdType.sequenceHexRandomized) {
                counter = randomInitialSeed();
            } else {
                counter = 0;
            }
            MongoCollection<Document> countersColl = mongoDBRepository.getCountersCollection();
            Document idCounter = new Document();
            idCounter.put(MONGODB_ID, COUNTER_NAME_UUID);
            idCounter.put(COUNTER_FIELD, Long.valueOf(counter));
            countersColl.insertOne(idCounter);
        }
        initRoot();
    }
protected void initRepository ( MongoDBRepositoryDescriptor descriptor ) { if ( coll . countDocuments ( converter . filterEq ( KEY_ID , getRootId ( ) ) ) > 0 ) { return ; } if ( useCustomId ) { coll . createIndex ( Indexes . ascending ( KEY_ID ) , new IndexOptions ( ) . unique ( true ) ) ; } coll . createIndex ( Indexes . ascending ( KEY_PARENT_ID ) ) ; coll . createIndex ( Indexes . ascending ( KEY_ANCESTOR_IDS ) ) ; coll . createIndex ( Indexes . ascending ( KEY_VERSION_SERIES_ID ) ) ; coll . createIndex ( Indexes . ascending ( KEY_PROXY_TARGET_ID ) ) ; coll . createIndex ( Indexes . ascending ( KEY_PROXY_VERSION_SERIES_ID ) ) ; coll . createIndex ( Indexes . ascending ( KEY_READ_ACL ) ) ; IndexOptions parentNameIndexOptions = new IndexOptions ( ) ; if ( descriptor != null ) { parentNameIndexOptions . unique ( Boolean . TRUE . equals ( descriptor . getChildNameUniqueConstraintEnabled ( ) ) ) ; } coll . createIndex ( Indexes . ascending ( KEY_PARENT_ID , KEY_NAME ) , parentNameIndexOptions ) ; coll . createIndex ( Indexes . ascending ( KEY_PRIMARY_TYPE ) ) ; coll . createIndex ( Indexes . ascending ( KEY_LIFECYCLE_STATE ) ) ; coll . createIndex ( Indexes . ascending ( KEY_IS_TRASHED ) ) ; coll . createIndex ( Indexes . ascending ( KEY_RETAIN_UNTIL ) ) ; if ( ! repository . isFulltextDisabled ( ) ) { coll . createIndex ( Indexes . ascending ( KEY_FULLTEXT_JOBID ) ) ; } coll . createIndex ( Indexes . ascending ( KEY_ACP + "." + KEY_ACL + "." + KEY_ACE_USER ) ) ; coll . createIndex ( Indexes . ascending ( KEY_ACP + "." + KEY_ACL + "." + KEY_ACE_STATUS ) ) ; coll . createIndex ( Indexes . descending ( "dc:modified" ) ) ; coll . createIndex ( Indexes . ascending ( "rend:renditionName" ) ) ; coll . createIndex ( Indexes . ascending ( "rend:sourceId" ) ) ; coll . createIndex ( Indexes . ascending ( "rend:sourceVersionableId" ) ) ; coll . createIndex ( Indexes . ascending ( "drv:subscriptions.enabled" ) ) ; coll . createIndex ( Indexes . ascending ( "collectionMember:collectionIds" ) ) ; coll . createIndex ( Indexes . ascending ( "nxtag:tags" ) ) ; coll . createIndex ( Indexes . ascending ( "coldstorage:beingRetrieved" ) ) ; if ( ! repository . isFulltextSearchDisabled ( ) ) { Bson indexKeys = Indexes . compoundIndex ( Indexes . text ( KEY_FULLTEXT_SIMPLE ) , Indexes . text ( KEY_FULLTEXT_BINARY ) ) ; IndexOptions indexOptions = new IndexOptions ( ) . name ( FULLTEXT_INDEX_NAME ) . languageOverride ( LANGUAGE_FIELD ) ; coll . createIndex ( indexKeys , indexOptions ) ; } IdType idType = repository . getIdType ( ) ; if ( idType == IdType . sequence || idType == IdType . sequenceHexRandomized || DBSRepositoryBase . DEBUG_UUIDS ) { long counter ; if ( idType == IdType . sequenceHexRandomized ) { counter = randomInitialSeed ( ) ; } else { counter = 0 ; } MongoCollection < Document > countersColl = mongoDBRepository . getCountersCollection ( ) ; Document idCounter = new Document ( ) ; idCounter . put ( MONGODB_ID , COUNTER_NAME_UUID ) ; idCounter . put ( COUNTER_FIELD , Long . valueOf ( counter ) ) ; countersColl . insertOne ( idCounter ) ; } initRoot ( ) ; }
Initializes the MongoDB repository
 @param descriptor the MongoDB repository descriptor
 @since 11.1
Initializes the MongoDB repository @param descriptor the MongoDB repository descriptor @since 11 . 1
// check root presence // create required indexes // code does explicit queries on those // often used in user-generated queries // TODO configure these from somewhere else // // // // create basic repository structure needed // create the id counter