Example usage for com.mongodb DBCollection dropIndexes

List of usage examples for com.mongodb DBCollection dropIndexes

Introduction

In this page you can find the example usage for com.mongodb DBCollection dropIndexes.

Prototype

public void dropIndexes() 

Source Link

Document

Drop all indexes on this collection.

Usage

From source file:org.nuxeo.ecm.core.test.StorageConfiguration.java

License:Apache License

protected void clearMongoDB(MongoDBRepositoryDescriptor descriptor) throws UnknownHostException {
    MongoClient mongoClient = MongoDBRepository.newMongoClient(descriptor);
    try {//from  ww  w  .  ja va2  s.co m
        DBCollection coll = MongoDBRepository.getCollection(descriptor, mongoClient);
        coll.dropIndexes();
        coll.remove(new BasicDBObject());
        coll = MongoDBRepository.getCountersCollection(descriptor, mongoClient);
        coll.dropIndexes();
        coll.remove(new BasicDBObject());
    } finally {
        mongoClient.close();
    }
}

From source file:org.springframework.data.mongodb.test.util.CleanMongoDB.java

License:Apache License

private void dropCollectionsOrIndexIfRequried(DB db, Collection<String> collectionsToUse) {

    for (String collectionName : collectionsToUse) {

        if (db.collectionExists(collectionName)) {

            DBCollection collection = db.getCollectionFromString(collectionName);
            if (collection != null) {

                if (types.contains(Struct.COLLECTION)) {
                    collection.drop();//from   w  w w. ja v a2s  .c  o  m
                    LOGGER.debug("Dropping collection '{}' for DB '{}'. ", collectionName, db.getName());
                } else if (types.contains(Struct.INDEX)) {
                    collection.dropIndexes();
                    LOGGER.debug("Dropping indexes in collection '{}' for DB '{}'. ", collectionName,
                            db.getName());
                }
            }
        }
    }
}

From source file:serwlety.szukaj.DaneSzukaj.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from w ww.  j a  va 2  s .  c om
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    DBCollection db = baza.FabrykaPolaczenia.getInstance().getConnection().getCollection("Osoba");
    db.createIndex(new BasicDBObject("$**", "text"));
    DBObject d = QueryBuilder.start().text(request.getParameter("slowa")).get();
    DBCursor cursor = db.find(d);
    List<DBObject> wyniki = new ArrayList<>();
    while (cursor.hasNext()) {
        wyniki.add(cursor.next());
    }
    db.dropIndexes();
    request.setAttribute("wyniki", wyniki);
    String slowa = request.getParameter("slowa");
    request.setAttribute("slowa", request.getParameter("slowa"));
    request.getRequestDispatcher("/WEB-INF/szukaj/daneWyniki.jsp").forward(request, response);
}