/** * Ensures an index on this collection (that is, the index will be created if it does not exist). * * @param keys fields to use for index * @param name an identifier for the index. If null or empty, the default name will be used. * @param unique if the index should be unique * @throws MongoException If an error occurred */ public void ensureIndex(DBObject keys, String name, boolean unique) throws MongoException { dbCollection.ensureIndex(keys, name, unique); }
/** * calls {@link DBCollection#ensureIndex(com.mongodb.DBObject, com.mongodb.DBObject)} with default options * * @param keys an object with a key set of the fields desired for the index * @throws MongoException If an error occurred */ public final void ensureIndex(final DBObject keys) throws MongoException { dbCollection.ensureIndex(keys); }
/** * calls {@link DBCollection#ensureIndex(com.mongodb.DBObject, com.mongodb.DBObject)} with default options * * @param keys an object with a key set of the fields desired for the index * @throws MongoException If an error occurred */ public final void ensureIndex(final DBObject keys) throws MongoException { dbCollection.ensureIndex(keys); }
/** * Creates an index on a set of fields, if one does not already exist. * * @param keys an object with a key set of the fields desired for the index * @param optionsIN options for the index (name, unique, etc) * @throws MongoException If an error occurred */ public void ensureIndex(final DBObject keys, final DBObject optionsIN) throws MongoException { dbCollection.ensureIndex(keys, optionsIN); }
/** * Ensures an index on this collection (that is, the index will be created if it does not exist). * * @param keys fields to use for index * @param name an identifier for the index. If null or empty, the default name will be used. * @param unique if the index should be unique * @throws MongoException If an error occurred */ public void ensureIndex(DBObject keys, String name, boolean unique) throws MongoException { dbCollection.ensureIndex(keys, name, unique); }
/** * Creates an index on a set of fields, if one does not already exist. * * @param keys an object with a key set of the fields desired for the index * @param optionsIN options for the index (name, unique, etc) * @throws MongoException If an error occurred */ public void ensureIndex(final DBObject keys, final DBObject optionsIN) throws MongoException { dbCollection.ensureIndex(keys, optionsIN); }
private void initIndex() { // Make sure we have a unique index on name BasicDBObject keys=new BasicDBObject(NAME,1); BasicDBObject options=new BasicDBObject("unique",1); coll.ensureIndex(keys,options); }
public void init(DBCollection coll) { // Make sure we have a unique index on resourceid this.coll=coll; BasicDBObject keys=new BasicDBObject(RESOURCEID,1); BasicDBObject options=new BasicDBObject("unique",1); this.coll.ensureIndex(keys,options); }
private void ensureIndex(String tag) { if(!seenTags.contains(tag)) { long start = System.currentTimeMillis(); documents.ensureIndex(MongoDocument.METADATA_KEY+"."+DatabaseDocument.FETCHED_METADATA_TAG+"."+tag); logger.info("Ensured index for stage "+tag+" in "+(System.currentTimeMillis()-start)+" ms"); seenTags.add(tag); } }
public void ensureIndex(String element, String field, boolean asc) { DBObject index = new BasicDBObject(); index.put(element + "." + field, asc ? 1 : -1); collection.ensureIndex(index); }
public void ensureIndex(String element, String... fields) { DBObject index = new BasicDBObject(); for (String field : fields) { index.put(element + "." + field, 1); } collection.ensureIndex(index); }
DBObject index2d = BasicDBObjectBuilder.start("location", "2dsphere").get(); DBCollection collection = new Mongo().getDB("yourdb").getCollection("yourcollection"); collection.ensureIndex(index2d);
/** * Creates a RrdMongoDBBackendFactory. Make sure that the passed {@link DBCollection} has a safe write * concern, is capped (if needed) and slaveOk() called if applicable. * * @param rrdCollection the collection to use for storing RRD byte data */ public RrdMongoDBBackendFactory(DBCollection rrdCollection) { this.rrdCollection = rrdCollection; // make sure we have an index on the path field rrdCollection.ensureIndex(new BasicDBObject("path", 1)); // set the RRD backend factory RrdBackendFactory.registerAndSetAsDefaultFactory(this); }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); try { MongoConnection conn = new MongoConnection(db_connection, safeMode); coll = conn.coll; // index pmid (an integer, unlike _id),useful for queries coll.ensureIndex(PM_ID); } catch (IOException e) { throw new ResourceInitializationException(e); } }
private void _ensureIndex(String name, Boolean isUnique, Boolean isSparse, String... fields) { final DBObject options = new BasicDBObject(OPTION_NAME, name); options.put(OPTION_SPARSE, isSparse.booleanValue()); if (isUnique){ options.put(OPTION_UNIQUE, isUnique); } final DBObject index = new BasicDBObject(); for (String field : fields) { index.put(field, 1); } LOGGER.info(this.getClass().getSimpleName() +": Executin ensure index " + index+ " with options " + options); getCollection().ensureIndex(index, options); }
protected static void index(Map keys, Map indexOptions) { parent$_collection.ensureIndex(translateMapToDBObject(keys), translateMapToDBObject(indexOptions)); }
@Override synchronized public void open() { super.open(); conflicts = ((MongoObjectDatabase) super.stagingDb).getCollection("conflicts"); conflicts.ensureIndex("path"); }
public static void ensureIndex(DBCollection collection, String fieldName, boolean unique, boolean sparse) { BasicDBObject indexKey = new BasicDBObject(); indexKey.put(fieldName, 1); BasicDBObject option = new BasicDBObject(); if (sparse) { option.put("sparse", true); } if (unique) { option.put("unique", true); } collection.ensureIndex(indexKey, option); }
private void initBlobCollection() { if (db.collectionExists(COLLECTION_BLOBS)) { return; } DBCollection collection = getBlobCollection(); DBObject index = new BasicDBObject(); index.put(MongoBlob.KEY_ID, 1L); DBObject options = new BasicDBObject(); options.put("unique", Boolean.TRUE); collection.ensureIndex(index, options); }
@Override public synchronized void open() { if (client != null) { return; } String uri = config.get("mongodb.uri").get(); String database = config.get("mongodb.database").get(); client = manager.acquire(new MongoAddress(uri)); db = client.getDB(database); collection = db.getCollection(getCollectionName()); collection.ensureIndex("oid"); }