当前位置: 首页>>代码示例>>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;未经允许,请勿转载。