當前位置: 首頁>>代碼示例>>Java>>正文


Java DBCollection.createIndex方法代碼示例

本文整理匯總了Java中com.mongodb.DBCollection.createIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java DBCollection.createIndex方法的具體用法?Java DBCollection.createIndex怎麽用?Java DBCollection.createIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.DBCollection的用法示例。


在下文中一共展示了DBCollection.createIndex方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import com.mongodb.DBCollection; //導入方法依賴的package包/類
/**
 * Init registry.
 **/
@PostConstruct
public void initialize() {
    Assert.notNull(this.mongoTemplate);

    LOGGER.debug("Setting up MongoDb Ticket Registry instance [{}]", this.collectionName);
    if (this.dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
    LOGGER.debug("Creating indices on collection [{}] to auto-expire documents...", this.collectionName);
    final DBCollection collection = mongoTemplate.getCollection(this.collectionName);
    collection.createIndex(new BasicDBObject(TicketHolder.FIELD_NAME_EXPIRE_AT, 1),
            new BasicDBObject("expireAfterSeconds", 0));

    LOGGER.info("Configured MongoDb Ticket Registry instance [{}]", this.collectionName);
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:25,代碼來源:MongoDbTicketRegistry.java

示例2: addSocialUserConnection

import com.mongodb.DBCollection; //導入方法依賴的package包/類
@ChangeSet(order = "03", author = "initiator", id = "03-addSocialUserConnection")
public void addSocialUserConnection(DB db) {
    DBCollection socialUserConnectionCollection = db.getCollection("jhi_social_user_connection");
    socialUserConnectionCollection.createIndex(BasicDBObjectBuilder
            .start("user_id", 1)
            .add("provider_id", 1)
            .add("provider_user_id", 1)
            .get(),
        "user-prov-provusr-idx", true);
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:11,代碼來源:InitialSetupMigration.java

示例3: addUsers

import com.mongodb.DBCollection; //導入方法依賴的package包/類
@ChangeSet(order = "02", author = "initiator", id = "02-addUsers")
public void addUsers(DB db) {
    DBCollection usersCollection = db.getCollection("jhi_user");
    usersCollection.createIndex("login");
    usersCollection.createIndex("email");
    usersCollection.insert(BasicDBObjectBuilder.start()
        .add("_id", "user-0")
        .add("login", "system")
        .add("password", "*************")
        .add("first_name", "")
        .add("last_name", "System")
        .add("email", "[email protected]")
        .add("activated", "true")
        .add("lang_key", "en")
        .add("created_by", "system")
        .add("created_date", new Date())
        .add("authorities", authoritiesAdminAndUser)
        .get()
    );
    usersCollection.insert(BasicDBObjectBuilder.start()
        .add("_id", "user-1")
        .add("login", "anonymousUser")
        .add("password", "*************")
        .add("first_name", "Anonymous")
        .add("last_name", "User")
        .add("email", "[email protected]")
        .add("activated", "true")
        .add("lang_key", "en")
        .add("created_by", "system")
        .add("created_date", new Date())
        .add("authorities", new Map[]{})
        .get()
    );
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:35,代碼來源:InitialSetupMigration.java

示例4: createIndexes

import com.mongodb.DBCollection; //導入方法依賴的package包/類
protected void createIndexes() {
	DBCollection coll = getCollection();
	// create the indexes
	coll.createIndex(new BasicDBObject("key", 1));
	coll.createIndex(new BasicDBObject("lifeSpan", 1));
	//coll.createIndex(new BasicDBObject("timeIdle", 1)); Idle is not supported from version 2
	coll.createIndex(new BasicDBObject("expires", 1));
}
 
開發者ID:lucee,項目名稱:extension-mongodb,代碼行數:9,代碼來源:MongoDBCache.java

示例5: addSocialUserConnection

import com.mongodb.DBCollection; //導入方法依賴的package包/類
@ChangeSet(author = "initiator", id = "03-addSocialUserConnection", order = "03")
public void addSocialUserConnection(DB db) {
    DBCollection socialUserConnectionCollection = db.getCollection("jhi_social_user_connection");
    socialUserConnectionCollection.createIndex(BasicDBObjectBuilder
            .start("user_id", 1)
            .add("provider_id", 1)
            .add("provider_user_id", 1)
            .get(),
        "user-prov-provusr-idx", true);
}
 
開發者ID:axel-halin,項目名稱:Thesis-JHipster,代碼行數:11,代碼來源:_InitialSetupMigration.java

示例6: ensureIndex

import com.mongodb.DBCollection; //導入方法依賴的package包/類
/**
 * Ensures (creating if necessary) the index including the field(s) + directions; eg fields = "field1, -field2" ({field1:1, field2:-1})
 */
public void ensureIndex(String collName, String name, String fields, boolean unique, boolean dropDupsOnCreate) {

    BasicDBObject dbFields = parseFieldsString(fields);

    final BasicDBObjectBuilder keyOpts = new BasicDBObjectBuilder();
    if (name != null && name.length() != 0) {
        keyOpts.add("name", name);
    }
    if (unique) {
        keyOpts.add("unique", true);
        if (dropDupsOnCreate) {
            keyOpts.add("dropDups", true);
        }
    }

    final DBCollection dbColl = getCollection(getCollName(collName));

    final BasicDBObject opts = (BasicDBObject) keyOpts.get();
    if (opts.isEmpty()) {
        LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + dbFields);
        dbColl.createIndex(dbFields);
    } else {
        LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields + " and opts:" + opts);
        dbColl.createIndex(dbFields, opts);
    }
}
 
開發者ID:WenZuHuai,項目名稱:light-task-scheduler,代碼行數:30,代碼來源:MongoTemplate.java

示例7: addUsers

import com.mongodb.DBCollection; //導入方法依賴的package包/類
@ChangeSet(order = "02", author = "initiator", id = "02-addUsers")
public void addUsers(DB db) {
    DBCollection usersCollection = db.getCollection("jhi_user");
    usersCollection.createIndex("login");
    usersCollection.createIndex("email");
    usersCollection.insert(BasicDBObjectBuilder.start()
        .add("_id", "user-0")
        .add("login", "system")
        .add("password", "$2a$10$mE.qmcV0mFU5NcKh73TZx.z4ueI/.bDWbj0T1BYyqP481kGGarKLG")
        .add("first_name", "")
        .add("last_name", "System")
        .add("email", "[email protected]")
        .add("activated", "true")
        .add("lang_key", "en")
        .add("created_by", "system")
        .add("created_date", new Date())
        .add("authorities", authoritiesAdminAndUser)
        .get()
    );
    usersCollection.insert(BasicDBObjectBuilder.start()
        .add("_id", "user-1")
        .add("login", "anonymousUser")
        .add("password", "$2a$10$j8S5d7Sr7.8VTOYNviDPOeWX8KcYILUVJBsYV83Y5NtECayypx9lO")
        .add("first_name", "Anonymous")
        .add("last_name", "User")
        .add("email", "[email protected]")
        .add("activated", "true")
        .add("lang_key", "en")
        .add("created_by", "system")
        .add("created_date", new Date())
        .add("authorities", new Map[]{})
        .get()
    );
    usersCollection.insert(BasicDBObjectBuilder.start()
        .add("_id", "user-2")
        .add("login", "admin")
        .add("password", "$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC")
        .add("first_name", "admin")
        .add("last_name", "Administrator")
        .add("email", "[email protected]")
        .add("activated", "true")
        .add("lang_key", "en")
        .add("created_by", "system")
        .add("created_date", new Date())
        .add("authorities", authoritiesAdminAndUser)
        .get()
    );
    usersCollection.insert(BasicDBObjectBuilder.start()
        .add("_id", "user-3")
        .add("login", "user")
        .add("password", "$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K")
        .add("first_name", "")
        .add("last_name", "User")
        .add("email", "[email protected]")
        .add("activated", "true")
        .add("lang_key", "en")
        .add("created_by", "system")
        .add("created_date", new Date())
        .add("authorities", authoritiesUser)
        .get()
    );
}
 
開發者ID:axel-halin,項目名稱:Thesis-JHipster,代碼行數:63,代碼來源:InitialSetupMigration.java

示例8: openMongoDb

import com.mongodb.DBCollection; //導入方法依賴的package包/類
public DBCollection openMongoDb() throws UnknownHostException {

    	MongoClientURI dbUri = new MongoClientURI(dbUriStr_+"?socketTimeoutMS=180000");
	    mongoClient_ = new MongoClient(dbUri);

	    DB db = mongoClient_.getDB( dbName_ );
	    DBCollection coll = db.getCollection(collection_);
	    coll.createIndex(new BasicDBObject(index_, 1));  // create index on "i", ascending

	    return coll;

    }
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:13,代碼來源:MongoWrapper.java


注:本文中的com.mongodb.DBCollection.createIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。