本文整理汇总了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);
}
示例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);
}
示例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()
);
}
示例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));
}
示例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);
}
示例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);
}
}
示例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()
);
}
示例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;
}