本文整理汇总了Java中com.mongodb.client.model.Indexes.ascending方法的典型用法代码示例。如果您正苦于以下问题:Java Indexes.ascending方法的具体用法?Java Indexes.ascending怎么用?Java Indexes.ascending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.client.model.Indexes
的用法示例。
在下文中一共展示了Indexes.ascending方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}
示例5: ascending
import com.mongodb.client.model.Indexes; //导入方法依赖的package包/类
public MongoIndex ascending(String... keys) {
this.bson = Indexes.ascending(keys);
return this;
}