Java Code Examples for com.mongodb.client.model.IndexOptions#background()
The following examples show how to use
com.mongodb.client.model.IndexOptions#background() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProfilingWriter.java From mongodb-slow-operations-profiler with GNU Affero General Public License v3.0 | 6 votes |
public ProfilingWriter(BlockingQueue<ProfilingEntry> jobQueue) { this.jobQueue = jobQueue; serverDto = ConfigReader.getCollectorServer(); runningSince = new Date(); final MongoDbAccessor mongo = getMongoDbAccessor(); try { final MongoCollection<Document> profileCollection = getProfileCollection(mongo); 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); LOG.info("ProfilingWriter is ready at {}", serverDto.getHosts()); } catch (MongoException e) { LOG.error("Exception while connecting to: {}", serverDto.getHosts(), e); } }
Example 2
Source File: ProfilingWriter.java From mongodb-slow-operations-profiler with GNU Affero General Public License v3.0 | 6 votes |
private void init(MongoDbAccessor mongo) { LOG.info(">>> init"); try { final MongoCollection<Document> profileCollection = getProfileCollection(mongo); 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); ApplicationStatusDto.addWebLog("ProfilingWriter is successfully connected to its collector database."); } catch (MongoException e) { LOG.error("Exception while connecting to: {}", serverDto.getHosts(), e); ApplicationStatusDto.addWebLog("ProfilingWriter could not connect to its collector database."); } LOG.info("<<< init"); }
Example 3
Source File: IndexOptionsMemoryOperation.java From jphp with Apache License 2.0 | 6 votes |
@Override public IndexOptions convert(Environment env, TraceInfo trace, Memory arg) throws Throwable { if (arg.isNull()) return null; ArrayMemory arr = arg.toValue(ArrayMemory.class); IndexOptions options = new IndexOptions(); if (arr.containsKey("background")) { options.background(arg.valueOfIndex("background").toBoolean()); } if (arr.containsKey("defaultLanguage")) { options.defaultLanguage(arg.valueOfIndex("defaultLanguage").toString()); } if (arr.containsKey("bits")) { options.bits(arg.valueOfIndex("bits").toInteger()); } if (arr.containsKey("name")) { options.name(arg.valueOfIndex("name").toString()); } if (arr.containsKey("max")) { options.max(arg.valueOfIndex("max").toDouble()); } if (arr.containsKey("min")) { options.min(arg.valueOfIndex("min").toDouble()); } if (arr.containsKey("languageOverride")) { options.languageOverride(arg.valueOfIndex("languageOverride").toString()); } if (arr.containsKey("sparse")) { options.sparse(arg.valueOfIndex("sparse").toBoolean()); } if (arr.containsKey("unique")) { options.unique(arg.valueOfIndex("unique").toBoolean()); } if (arr.containsKey("version")) { options.version(arg.valueOfIndex("version").toInteger()); } if (arr.containsKey("textVersion")) { options.textVersion(arg.valueOfIndex("textVersion").toInteger()); } if (arr.containsKey("sphereVersion")) { options.sphereVersion(arg.valueOfIndex("sphereVersion").toInteger()); } return options; }
Example 4
Source File: AbstractOperation.java From mongodb-performance-test with GNU Affero General Public License v3.0 | 5 votes |
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); }
Example 5
Source File: ExampleSlowOpsCache.java From mongodb-slow-operations-profiler with GNU Affero General Public License v3.0 | 5 votes |
private ExampleSlowOpsCache(){ cache = new HashSet<>(); serverDto = ConfigReader.getCollectorServer(); readLock = globalLock.readLock(); writeLock = globalLock.writeLock(); final MongoDbAccessor mongo = new MongoDbAccessor(serverDto.getAdminUser(), serverDto.getAdminPw(), serverDto.getSsl(), serverDto.getHosts()); try { exampleCollection = getExampleCollection(mongo); final IndexOptions indexOptions = new IndexOptions(); indexOptions.background(true); //index for retrieval by fingerprint (don't make it unique in case of collisions by the hashing algorithm) LOG.info("Create index {fp:1} in the background if it does not yet exists"); exampleCollection.createIndex(new BasicDBObject("fp", 1), indexOptions); //index for removing old entries // e.g. when the slow ops collection is a capped collection // then entries older than the oldest slow op can be removed from the example collection // (the entry may be added automatically anew if the corresponding query is collected again) LOG.info("Create index {ts:1} in the background if it does not yet exists"); exampleCollection.createIndex(new BasicDBObject("ts", 1), indexOptions); loadCache(exampleCollection); LOG.info("ExampleSlowOpsCache is ready at {}", serverDto.getHosts()); } catch (MongoException e) { LOG.error("Exception while connecting to: {}", serverDto.getHosts(), e); } }