本文整理汇总了Java中com.mongodb.client.model.Indexes类的典型用法代码示例。如果您正苦于以下问题:Java Indexes类的具体用法?Java Indexes怎么用?Java Indexes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Indexes类属于com.mongodb.client.model包,在下文中一共展示了Indexes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initCollections
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private static void initCollections(MongoDatabase db) {
try {
db.createCollection("users");
db.createCollection("categories");
db.createCollection("feeds");
db.createCollection("licenses");
} catch (Exception e) {
Log.w(TAG, "[attemptCreateCollections] " + e.getMessage());
}
users = db.getCollection("users");
categories = db.getCollection("categories");
feeds = db.getCollection("feeds");
licenses = db.getCollection("licenses");
users.createIndex(
Indexes.ascending(User.USERNAME),
new IndexOptions().unique(true));
categories.createIndex(
Indexes.ascending(Category.OWNER, Category.KEY),
new IndexOptions().unique(true));
}
示例2: ensureIndexes
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public static <T extends OkraItem> void ensureIndexes(final Okra<T> okra,
final MongoClient mongo,
final String database,
final String collection) {
okra.getIndexDefs()
.stream()
.map(indexDef -> {
final boolean ascending = indexDef.getOrdering() == null
|| indexDef.getOrdering().equals(Ordering.ASC);
final Bson ordering = ascending
? Indexes.ascending(indexDef.getAttrs()) : Indexes.descending(indexDef.getAttrs());
return mongo
.getDatabase(database)
.getCollection(collection)
.createIndex(ordering);
})
.forEach(indexName -> LOGGER.info("Done. Index name: {}", indexName));
}
示例3: indexCollection
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public void indexCollection(final String collectionName, final String field) {
// Sanity checks
if (StringUtils.isEmpty(collectionName)) {
throw new IllegalArgumentException("count :: Collection name should not be blank");
}
// Collection
MongoCollection<Document> collection = this.database.getCollection(collectionName);
collection.createIndex(Indexes.descending(field));
}
示例4: fromSmofIndexField
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private static Bson fromSmofIndexField(SmofIndexField field) {
final String fieldName = field.name();
switch(field.type()) {
case ASCENDING:
return Indexes.ascending(fieldName);
case DESCENDING:
return Indexes.descending(fieldName);
case TEXT:
return Indexes.text(fieldName);
}
handleError(new IllegalArgumentException("Invalid index field."));
return null;
}
示例5: createRawIndexes
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private static Set<Bson> createRawIndexes(BsonDocument doc) {
final Set<Bson> indexes = new LinkedHashSet<>();
final String name = doc.getString("name").getValue();
if(name.equals("_id_")) {
indexes.add(Indexes.ascending(Element.ID));
}
else {
indexes.addAll(parseIndexName(name));
}
return indexes;
}
示例6: nextIndex
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private static Bson nextIndex(StringTokenizer tokens) {
final Bson index;
final StringBuilder indexName = new StringBuilder(tokens.nextToken());
String indexTypeStr = tokens.nextToken();
IndexType indexT;
while((indexT = IndexType.parse(indexTypeStr)) == null) {
indexName.append("_").append(indexTypeStr);
indexTypeStr = tokens.nextToken();
}
switch(indexT) {
case ASCENDING:
index = Indexes.ascending(indexName.toString());
break;
case DESCENDING:
index = Indexes.descending(indexName.toString());
break;
case TEXT:
index = Indexes.text(indexName.toString());
break;
default:
handleError(new IllegalArgumentException("Invalid bson index"));
index = null;
break;
}
return index;
}
示例7: run
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
@Override
public void run(Environment environment, Namespace namespace, SamConfiguration configuration) throws Exception {
final MongoDatabase database = configuration.getDbConnectionFactory().getDatabase(environment.lifecycle());
final MongoCollection<Document> servers = database.getCollection(Collections.SERVERS);
servers.createIndexes(Lists.newArrayList(
new IndexModel(
ascending("fqdn"),
new IndexOptions().unique(true).sparse(true)
),
new IndexModel(
compoundIndex(ascending("hostname"), ascending("environment")),
new IndexOptions().unique(true)
),
new IndexModel(
compoundIndex(Indexes.text("hostname"), Indexes.text("environment"), Indexes.text("fqdn"), Indexes.text("description")),
new IndexOptions().weights(new Document().append("hostname", 10).append("fqdn", 10).append("environment", 5)).defaultLanguage("sv")
)
));
final MongoCollection<Document> applications = database.getCollection(Collections.APPLICATIONS);
applications.createIndexes(Lists.newArrayList(
new IndexModel(
ascending("id"),
new IndexOptions().unique(true)
),
new IndexModel(
compoundIndex(Indexes.text("id"), Indexes.text("name"), Indexes.text("description")),
new IndexOptions().weights(new Document().append("id", 10).append("name", 10)).defaultLanguage("sv")
)
));
final MongoCollection<Document> groups = database.getCollection(Collections.GROUPS);
groups.createIndexes(Lists.newArrayList(
new IndexModel(
ascending("id"),
new IndexOptions().unique(true)
),
new IndexModel(
ascending("tags")
),
new IndexModel(
compoundIndex(Indexes.text("id"), Indexes.text("name"), Indexes.text("description"), Indexes.text("tags")),
new IndexOptions().weights(new Document().append("id", 10).append("name", 10).append("tags", 5)).defaultLanguage("sv")
)
));
final MongoCollection<Document> assets = database.getCollection(Collections.ASSETS);
assets.createIndexes(Lists.newArrayList(
new IndexModel(
ascending("id"),
new IndexOptions().unique(true)
),
new IndexModel(
compoundIndex(Indexes.text("id"), Indexes.text("name"), Indexes.text("description")),
new IndexOptions().weights(new Document().append("id", 10).append("name", 10)).defaultLanguage("sv")
)
));
}
示例8: createMongoDocIdIndex
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public static void createMongoDocIdIndex(String collectionName) {
IndexOptions indexOptions = new IndexOptions().unique(true).background(true);
MongoCollection<org.bson.Document> collection = mongoClient.getDatabase("mdw").getCollection(collectionName);
String indexName = collection.createIndex(Indexes.ascending("document_id"), indexOptions);
LoggerUtil.getStandardLogger().mdwDebug("Created Index : " + indexName + " on collection : " + collectionName);
collectionDocIdIndexed.putIfAbsent(collectionName, Boolean.valueOf(true));
}
示例9: start
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
@Override
public void start() throws IOException {
MongoClientURI clientURI = new MongoClientURI(mongoURL);
client = new MongoClient(clientURI);
MongoDatabase db = client.getDatabase(clientURI.getDatabase());
collection = db.getCollection(clientURI.getCollection()).withWriteConcern(WriteConcern.JOURNALED);
Bson index = Indexes.ascending(pKey);
collection.createIndex(index);
}
示例10: createDbAndCollections
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private static void createDbAndCollections(String dbName,
String collectionName, String indexFieldName) {
MongoDatabase db = mongoClient.getDatabase(dbName);
MongoCollection<Document> mongoCollection = db
.getCollection(collectionName);
if (mongoCollection == null) {
db.createCollection(collectionName);
mongoCollection = db.getCollection(collectionName);
}
IndexOptions indexOptions = new IndexOptions().unique(true)
.background(false).name(indexFieldName);
Bson keys = Indexes.ascending(indexFieldName);
mongoCollection.createIndex(keys, indexOptions);
}
示例11: createIndexes
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
@PostConstruct
public void createIndexes() {
if (!indexExists(User.class, CUser.email)) {
this.getCollection(User.class).createIndex(Indexes.ascending(CUser.email),
new IndexOptions().unique(true));
}
if (!indexExists(PersistentLogin.class, CPersistentLogin.userId)) {
this.getCollection(PersistentLogin.class)
.createIndex(Indexes.ascending(CPersistentLogin.userId));
}
}
示例12: setUp
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MongoDatabase db = mongo.getDatabase(DATABASE_NAME);
db.createCollection(TEST_WRITE_COLLECTION);
db.createCollection(UNIQUE_KEY_EXCEPTION_COLLECTION);
testWriteCollection = db.getCollection(TEST_WRITE_COLLECTION);
testWriteCollection.createIndex(Indexes.text("name"), new IndexOptions().unique(true));
}
示例13: QueryManager
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public QueryManager(ThreadFactory tf, MongoCollection<Document> db, ReportManager reportManager, I18n i18n, PluginContainer plugin)
{
this.db = db;
this.reportManager = reportManager;
this.i18n = i18n;
storeExecuter = newSingleThreadExecutor(tf);
queryShowExecutor = Sponge.getScheduler().createSyncExecutor(plugin);
this.plugin = plugin;
db.createIndex(Indexes.hashed("type"));
db.createIndex(Indexes.descending("date"));
db.createIndex(Indexes.ascending("data.location.Position_X", "data.location.Position_Z", "data.location.Position_Y"));
db.createIndex(Indexes.hashed("data.location.WorldUuid"));
}
示例14: fromIndexes
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private Bson fromIndexes(List<Bson> indexes) {
if(indexes.size() == 1) {
return indexes.get(0);
}
return Indexes.compoundIndex(indexes);
}
示例15: ascending
import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public MongoIndex ascending(String... keys) {
this.bson = Indexes.ascending(keys);
return this;
}