Tabnine Logo
IndexOptions.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
com.mongodb.client.model.IndexOptions
constructor

Best Java code snippets using com.mongodb.client.model.IndexOptions.<init> (Showing top 20 results out of 522)

origin: org.mongodb/mongo-java-driver

/**
 * Construct an instance with the given keys.
 *
 * @param keys the index keys
 */
public IndexModel(final Bson keys) {
  this(keys, new IndexOptions());
}
origin: org.mongodb/mongo-java-driver

@Override
public String createIndex(final Bson keys) {
  return createIndex(keys, new IndexOptions());
}
origin: stackoverflow.com

 Document keys = new Document("email", 1);
collection.createIndex(keys, new IndexOptions().unique(true));
origin: org.mongodb/mongo-java-driver

@Override
public String createIndex(final ClientSession clientSession, final Bson keys) {
  return createIndex(clientSession, keys, new IndexOptions());
}
origin: prestodb/presto

private void createTableMetadata(SchemaTableName schemaTableName, List<MongoColumnHandle> columns)
    throws TableNotFoundException
{
  String schemaName = schemaTableName.getSchemaName();
  String tableName = schemaTableName.getTableName();
  MongoDatabase db = client.getDatabase(schemaName);
  Document metadata = new Document(TABLE_NAME_KEY, tableName);
  ArrayList<Document> fields = new ArrayList<>();
  if (!columns.stream().anyMatch(c -> c.getName().equals("_id"))) {
    fields.add(new MongoColumnHandle("_id", OBJECT_ID, true).getDocument());
  }
  fields.addAll(columns.stream()
      .map(MongoColumnHandle::getDocument)
      .collect(toList()));
  metadata.append(FIELDS_KEY, fields);
  MongoCollection<Document> schema = db.getCollection(schemaCollection);
  schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
  schema.insertOne(metadata);
}
origin: Graylog2/graylog2-server

private static void createIndex(MongoConnection mongoConnection) {
  final IndexOptions indexOptions = new IndexOptions()
      .name(INDEX_NAME)
      .unique(true);
  mongoConnection.getMongoDatabase()
      .getCollection(COLLECTION_NAME)
      .createIndex(Indexes.ascending("name"), indexOptions);
}
origin: jooby-project/jooby

private void syncTtl() {
 if (!ttlSync.get()) {
  ttlSync.set(true);
  if (timeout <= 0) {
   return;
  }
  log.debug("creating session timeout index");
  if (existsIdx(SESSION_IDX)) {
   Document command = new Document("collMod", collection)
     .append("index",
       new Document("keyPattern", new Document("_accessedAt", 1))
         .append("expireAfterSeconds", timeout));
   log.debug("{}", command);
   Document result = db.runCommand(command);
   log.debug("{}", result);
  } else {
   sessions.createIndex(
     new Document("_accessedAt", 1),
     new IndexOptions()
       .name(SESSION_IDX)
       .expireAfter(timeout, TimeUnit.SECONDS));
  }
 }
}
origin: prestodb/presto

private Document getTableMetadata(SchemaTableName schemaTableName)
    throws TableNotFoundException
{
  String schemaName = schemaTableName.getSchemaName();
  String tableName = schemaTableName.getTableName();
  MongoDatabase db = client.getDatabase(schemaName);
  MongoCollection<Document> schema = db.getCollection(schemaCollection);
  Document doc = schema
      .find(new Document(TABLE_NAME_KEY, tableName)).first();
  if (doc == null) {
    if (!collectionExists(db, tableName)) {
      throw new TableNotFoundException(schemaTableName);
    }
    else {
      Document metadata = new Document(TABLE_NAME_KEY, tableName);
      metadata.append(FIELDS_KEY, guessTableFields(schemaTableName));
      schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
      schema.insertOne(metadata);
      return metadata;
    }
  }
  return doc;
}
origin: Graylog2/graylog2-server

final IndexOptions indexOptions = new IndexOptions()
    .name(MongoDbGrokPatternService.INDEX_NAME)
    .unique(true);
origin: liuyangming/ByteTCC

private void createTransactionsGlobalTxKeyIndexIfNecessary() {
  String databaseName = CommonUtils.getApplication(this.endpoint).replaceAll("\\W", "_");
  MongoDatabase database = this.mongoClient.getDatabase(databaseName);
  MongoCollection<Document> transactions = database.getCollection(CONSTANTS_TB_TRANSACTIONS);
  ListIndexesIterable<Document> transactionIndexList = transactions.listIndexes();
  boolean transactionIndexExists = false;
  MongoCursor<Document> transactionCursor = null;
  try {
    transactionCursor = transactionIndexList.iterator();
    while (transactionIndexExists == false && transactionCursor.hasNext()) {
      Document document = transactionCursor.next();
      Boolean unique = document.getBoolean("unique");
      Document key = (Document) document.get("key");
      boolean globalExists = key.containsKey(CONSTANTS_FD_GLOBAL);
      boolean lengthEquals = key.size() == 1;
      transactionIndexExists = lengthEquals && globalExists;
      if (transactionIndexExists && (unique == null || unique == false)) {
        throw new IllegalStateException();
      }
    }
  } finally {
    IOUtils.closeQuietly(transactionCursor);
  }
  if (transactionIndexExists == false) {
    Document index = new Document(CONSTANTS_FD_GLOBAL, 1);
    transactions.createIndex(index, new IndexOptions().unique(true));
  }
}
origin: liuyangming/ByteTCC

private void createLocksIndexIfNecessary() {
  String databaseName = CommonUtils.getApplication(this.endpoint).replaceAll("\\W", "_");
  MongoDatabase database = this.mongoClient.getDatabase(databaseName);
  MongoCollection<Document> locks = database.getCollection(CONSTANTS_TB_LOCKS);
  ListIndexesIterable<Document> lockIndexList = locks.listIndexes();
  boolean transactionIndexExists = false;
  MongoCursor<Document> lockCursor = null;
  try {
    lockCursor = lockIndexList.iterator();
    while (transactionIndexExists == false && lockCursor.hasNext()) {
      Document document = lockCursor.next();
      Boolean unique = document.getBoolean("unique");
      Document key = (Document) document.get("key");
      boolean globalExists = key.containsKey(CONSTANTS_FD_GLOBAL);
      boolean lengthEquals = key.size() == 1;
      transactionIndexExists = lengthEquals && globalExists;
      if (transactionIndexExists && (unique == null || unique == false)) {
        throw new IllegalStateException();
      }
    }
  } finally {
    IOUtils.closeQuietly(lockCursor);
  }
  if (transactionIndexExists == false) {
    Document index = new Document(CONSTANTS_FD_GLOBAL, 1);
    locks.createIndex(index, new IndexOptions().unique(true));
  }
}
origin: org.mongodb/mongo-java-driver

private void checkCreateIndex(@Nullable final ClientSession clientSession) {
  if (!checkedIndexes) {
    if (collectionIsEmpty(clientSession, filesCollection.withDocumentClass(Document.class).withReadPreference(primary()))) {
      Document filesIndex = new Document("filename", 1).append("uploadDate", 1);
      if (!hasIndex(clientSession, filesCollection.withReadPreference(primary()), filesIndex)) {
        createIndex(clientSession, filesCollection, filesIndex, new IndexOptions());
      }
      Document chunksIndex = new Document("files_id", 1).append("n", 1);
      if (!hasIndex(clientSession, chunksCollection.withReadPreference(primary()), chunksIndex)) {
        createIndex(clientSession, chunksCollection, chunksIndex, new IndexOptions().unique(true));
      }
    }
    checkedIndexes = true;
  }
}
origin: MorphiaOrg/morphia

@SuppressWarnings("deprecation")
com.mongodb.client.model.IndexOptions convert(final IndexOptions options, final boolean background) {
  if (options.dropDups()) {
    LOG.warn("Support for dropDups has been removed from the server.  Please remove this setting.");
  }
  com.mongodb.client.model.IndexOptions indexOptions = new com.mongodb.client.model.IndexOptions()
    .background(options.background() || background)
    .sparse(options.sparse())
    .unique(options.unique());
  if (!options.language().equals("")) {
    indexOptions.defaultLanguage(options.language());
  }
  if (!options.languageOverride().equals("")) {
    indexOptions.languageOverride(options.languageOverride());
  }
  if (!options.name().equals("")) {
    indexOptions.name(options.name());
  }
  if (options.expireAfterSeconds() != -1) {
    indexOptions.expireAfter((long) options.expireAfterSeconds(), TimeUnit.SECONDS);
  }
  if (!options.partialFilter().equals("")) {
    indexOptions.partialFilterExpression(Document.parse(options.partialFilter()));
  }
  if (!options.collation().locale().equals("")) {
    indexOptions.collation(convert(options.collation()));
  }
  return indexOptions;
}
origin: spring-projects/spring-data-mongodb

IndexOptions ops = new IndexOptions();
origin: pippo-java/pippo

/**
 * Create TTL index
 *
 * @param idleTime idle time in seconds
 * @see https://docs.mongodb.com/manual/core/index-ttl/
 */
private void createIndex(long idleTime) {
  try {
    this.sessions.createIndex(
        new Document(SESSION_TTL, 1),
        new IndexOptions()
        .expireAfter(idleTime, TimeUnit.SECONDS)
        .name(SESSION_INDEX_NAME));
  } catch (MongoException ex) {//update idle time
    this.sessions.dropIndex(SESSION_INDEX_NAME);
    this.sessions.createIndex(
        new Document(SESSION_TTL, 1),
        new IndexOptions()
        .expireAfter(idleTime, TimeUnit.SECONDS)
        .name(SESSION_INDEX_NAME));
  }
}
origin: jphp-group/jphp

@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;
}
origin: org.springframework.data/spring-data-mongodb

IndexOptions ops = new IndexOptions();
origin: ch.exense.step/core

private void createTimestampIndexWithTTL(MongoCollection<Document> collection, String attribute, Long ttl) {
  IndexOptions options = new IndexOptions();
  options.expireAfter(ttl, TimeUnit.SECONDS);
  createTimestampIndexWithOptions(collection, attribute, options);
}
origin: sitewhere/sitewhere

/**
 * Ensure that expected collection indexes exist.
 * 
 * @throws SiteWhereException
 */
protected void ensureIndexes() throws SiteWhereException {
getMongoClient().getUsersCollection().createIndex(new Document(MongoUser.PROP_USERNAME, 1),
  new IndexOptions().unique(true));
getMongoClient().getAuthoritiesCollection().createIndex(new Document(MongoGrantedAuthority.PROP_AUTHORITY, 1),
  new IndexOptions().unique(true));
}
origin: protegeproject/webprotege

@Override
public void ensureIndexes() {
  Document index = new Document();
  index.append(Tag.PROJECT_ID, 1);
  index.append(Tag.LABEL, 1);
  getCollection().createIndex(index, new IndexOptions().unique(true));
}
com.mongodb.client.modelIndexOptions<init>

Popular methods of IndexOptions

  • unique
    Should the index should be unique.
  • name
    Sets the name of the index.
  • background
    Should the index should be created in the background
  • expireAfter
    Sets the time to live for documents in the collection
  • sparse
    Should the index only references documents with the specified field
  • partialFilterExpression
    Sets the filter expression for the documents to be included in the index
  • defaultLanguage
    Sets the language for the text index.The language that determines the list of stop words and the rul
  • languageOverride
    Sets the name of the field that contains the language string.For text indexes, the name of the field
  • weights
    Sets the weighting object for use with a text index.An document that represents field and weight pai
  • bits
    Sets the number of precision of the stored geohash value of the location data in 2d indexes.
  • getName
    Gets the name of the index.
  • isUnique
    Gets if the index should be unique.
  • getName,
  • isUnique,
  • max,
  • min,
  • sphereVersion,
  • bucketSize,
  • collation,
  • getDefaultLanguage,
  • getLanguageOverride

Popular in Java

  • Parsing JSON documents to java classes using gson
  • scheduleAtFixedRate (ScheduledExecutorService)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getSystemService (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • JTextField (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now