本文整理汇总了Java中com.mongodb.client.model.IndexOptions.background方法的典型用法代码示例。如果您正苦于以下问题:Java IndexOptions.background方法的具体用法?Java IndexOptions.background怎么用?Java IndexOptions.background使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.client.model.IndexOptions
的用法示例。
在下文中一共展示了IndexOptions.background方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: internalSetupIndexes
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
private void internalSetupIndexes(Class<?> entityClass, MongoCollection<Document> collection) {
if (entityClass == null || collection == null) {
return;
}
MongoIndex[] indexes = entityClass.getAnnotationsByType(MongoIndex.class);
if (indexes != null && indexes.length > 0) {
for (MongoIndex index : indexes) {
Document indexDocument = new Document();
indexDocument.put(index.key(), index.direction());
IndexOptions options = new IndexOptions();
options.unique(index.unique());
options.background(index.background());
collection.createIndex(indexDocument, options);
}
}
}
示例2: createIndex
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
/**
*
* @param dbName
* @param collection
* @param keys
* @param options
*/
void createIndex(
String dbName,
String collection,
BsonDocument keys,
BsonDocument options) {
if (options == null) {
client
.getDatabase(dbName)
.getCollection(collection)
.createIndex(keys);
} else {
// need to find a way to get IndexOptions from json
IndexOptions io = new IndexOptions();
io.background(true);
client
.getDatabase(dbName)
.getCollection(collection)
.createIndex(keys, getIndexOptions(options));
}
}
示例3: init
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
private void init() {
LOG.info(">>> init");
try {
mongo = new MongoDbAccessor(serverDto.getAdminUser(), serverDto.getAdminPw(), serverDto.getHosts());
final MongoDatabase db = mongo.getMongoDatabase(serverDto.getDb());
profileCollection = db.getCollection(serverDto.getCollection());
if(profileCollection == null) {
throw new IllegalArgumentException("Can't continue without profile collection for " + serverDto.getHosts());
}
IndexOptions indexOptions = new IndexOptions();
indexOptions.background(true);
LOG.info("Create index {ts:-1, lbl:1} in the background if it does not yet exists");
profileCollection.createIndex(new BasicDBObject("ts",-1).append("lbl", 1), indexOptions);
LOG.info("Create index {adr:1, db:1, ts:-1} in the background if it does not yet exists");
profileCollection.createIndex(new BasicDBObject("adr",1).append("db",1).append("ts", -1), indexOptions);
} catch (MongoException e) {
LOG.error("Exception while connecting to: {}", serverDto.getHosts(), e);
}
LOG.info("<<< init");
}
示例4: createChange
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
private MongoIndexChange createChange (CompoundIndex index, boolean replace){
Document definition = Document.parse(index.def());
IndexOptions opts = new IndexOptions();
opts.name(index.name());
opts.unique(index.unique());
opts.sparse(index.sparse());
opts.background(index.background());
return new MongoIndexChange(index.name(), definition, opts, replace);
}
示例5: createIndex
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
/**
* 创建索引
*
* @param collectionName 集合
* @param indexName 索引名
* @param keys 键信息,如 securityCode:1
* @param isUnique 是否唯一索引
*/
public void createIndex(String collectionName, String indexName, Map<String, Integer> keys, boolean isUnique) {
MongoCollection collection = sMongoDatabase.getCollection(collectionName);
IndexOptions indexOptions = new IndexOptions();
indexOptions.background(true);
indexOptions.unique(isUnique);
indexOptions.name(indexName);
Map<String, Object> keyIndexs = new HashMap<>(16);
for (Map.Entry<String, Integer> entry : keys.entrySet()) {
keyIndexs.put(entry.getKey(), entry.getValue() > 0 ? 1 : entry.getValue() == 0 ? 0 : -1);
}
collection.createIndex(new Document(keyIndexs), indexOptions);
}
示例6: AbstractOperation
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
public AbstractOperation(MongoDbAccessor mongoDbAccessor, String db, String collection, String queriedField){
this.mongoDbAccessor = mongoDbAccessor;
mongoCollection = mongoDbAccessor.getMongoDatabase(db).getCollection(collection);
this.queriedField = queriedField;
final IndexOptions options = new IndexOptions();
options.background(false);
mongoCollection.createIndex(new BasicDBObject(queriedField, 1), options);
minId = getMinMax(mongoDbAccessor, queriedField, true);
maxId = getMinMax(mongoDbAccessor, queriedField, false);
}
示例7: PrepareSystem
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
private void PrepareSystem(POCTestOptions testOpts,POCTestResults results)
{
MongoDatabase db;
MongoCollection<Document> coll;
//Create indexes and suchlike
db = mongoClient.getDatabase(testOpts.databaseName);
coll = db.getCollection(testOpts.collectionName);
if(testOpts.emptyFirst)
{
coll.drop();
}
for(int x=0;x<testOpts.secondaryidx;x++)
{
coll.createIndex(new Document("fld"+x,1));
}
if (testOpts.fulltext)
{
IndexOptions options = new IndexOptions();
options.background(true);
BasicDBObject weights = new BasicDBObject();
weights.put("lorem", 15);
weights.put("_fulltext.text", 5);
options.weights(weights);
Document index = new Document();
index.put("$**", "text");
coll.createIndex(index, options);
}
results.initialCount = coll.count();
//Now have a look and see if we are sharded
//And how many shards and make sure that the collection is sharded
if(! testOpts.singleserver) {
ConfigureSharding(testOpts);
}
}
示例8: createIndex
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
protected void createIndex(String name, BasicDBList dbList, MongoCollection<Document> collection) {
if (dbList.isEmpty() || name == null) {
return;
}
BasicDBObject index = (BasicDBObject) dbList.get(0);
IndexOptions options = new IndexOptions().name(name);
if (dbList.size() > 1) {
BasicDBObject opts = (BasicDBObject) dbList.get(1);
if (opts.get("unique") != null && opts.get("unique") instanceof Boolean) {
options = options.unique(opts.getBoolean("unique"));
}
if (opts.get("expireAfterSeconds") != null && opts.get("expireAfterSeconds") instanceof Integer) {
options = options.expireAfter(Long.valueOf(opts.getInt("expireAfterSeconds")), TimeUnit.SECONDS);
}
if (opts.get("background") != null && opts.get("background") instanceof Boolean) {
options = options.background(opts.getBoolean("background"));
}
if (opts.get("bits") != null && opts.get("bits") instanceof Integer) {
options = options.bits(opts.getInt("bits"));
}
if (opts.get("bucketSize") != null && opts.get("bucketSize") instanceof Double) {
options = options.bucketSize(opts.getDouble("bucketSize"));
}
if (opts.get("defaultLanguage") != null && opts.get("defaultLanguage") instanceof String) {
options = options.defaultLanguage(opts.getString("defaultLanguage"));
}
if (opts.get("languageOverride") != null && opts.get("languageOverride") instanceof String) {
options = options.languageOverride(opts.getString("languageOverride"));
}
if (opts.get("min") != null && opts.get("min") instanceof Double) {
options = options.min(opts.getDouble("min"));
}
if (opts.get("max") != null && opts.get("max") instanceof Double) {
options = options.max(opts.getDouble("max"));
}
if (opts.get("sparse") != null && opts.get("sparse") instanceof Boolean) {
options = options.sparse(opts.getBoolean("sparse"));
}
if (opts.get("textVersion") != null && opts.get("textVersion") instanceof Integer) {
options = options.textVersion(opts.getInt("textVersion"));
}
if (opts.get("version") != null && opts.get("version") instanceof Integer) {
options = options.version(opts.getInt("version"));
}
if (opts.get("weights") != null && opts.get("weights") instanceof Bson) {
options = options.weights((Bson) opts.get("weights"));
}
}
collection.createIndex(new Document(index), options);
}
示例9: getIndexs
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
@Override
public List<IndexModel> getIndexs (T t) {
// 获取该类的属性
Field[] clazz_fields = clazz.getDeclaredFields();
// 获取T父对象的属性
Field[] superFields = superClazz.getDeclaredFields();
Field[] fields = new Field[clazz_fields.length + superFields.length];
// 合并T与T父对象的属性
System.arraycopy(clazz_fields, 0, fields, 0, clazz_fields.length);
// 合并T与T父对象的属性
System.arraycopy(superFields, 0, fields, clazz_fields.length, superFields.length);
// 创建索引序列
List<IndexModel> indexModels = new ArrayList<IndexModel>();
// 循环该类的属性
for (Field field: fields) {
// 如果属性被Index注解,那么
if (field.isAnnotationPresent(Index.class)) {
// 获取注解对象
Index index = field.getAnnotation(Index.class);
// MongoDB ObjectID主键或者不是主键
if(index.id() == true || index.key() == false) {
continue;
}
// 创建索引键
BasicDBObject keys = new BasicDBObject();
keys.append(field.getName(), index.order());
// 附加选项
IndexOptions indexOptions = new IndexOptions();
if(index.background()) {
indexOptions.background(index.background());
}
// 所有名字
if("".equals(index.name()) == false) {
indexOptions.name(index.name());
}
// 唯一字段
if(index.unique()) {
indexOptions.unique(index.unique());
}
if(index.sparse()) {
indexOptions.sparse(index.sparse());
}
// 创建索引
IndexModel indexModel = new IndexModel(keys,indexOptions);
// 索引
indexModels.add(indexModel);
}
}
return indexModels;
}