List of usage examples for com.mongodb DBCollection drop
public void drop()
From source file:org.eobjects.analyzer.storage.MongoDbStorageProvider.java
License:Open Source License
@Override public RowAnnotationFactory createRowAnnotationFactory() { try {//from w ww. j a v a 2s.c o m Mongo mongo = new Mongo(); DB db = mongo.getDB("analyzerbeans"); String name = "rowannotationfactory" + id.getAndIncrement(); DBCollection collection = db.createCollection(name, null); // drop the collection in case it already exists collection.drop(); collection = db.createCollection(name, null); return new MongoDbRowAnnotationFactory(collection); } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:org.exist.mongodb.xquery.mongodb.collection.Drop.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {//ww w . j av a 2 s. c o m // Verify clientid and get client String mongodbClientId = args[0].itemAt(0).getStringValue(); MongodbClientStore.getInstance().validate(mongodbClientId); MongoClient client = MongodbClientStore.getInstance().get(mongodbClientId); // Get parameters String dbname = args[1].itemAt(0).getStringValue(); String collection = args[2].itemAt(0).getStringValue(); // Get database and collection DB db = client.getDB(dbname); DBCollection dbcol = db.getCollection(collection); dbcol.drop(); return Sequence.EMPTY_SEQUENCE; } catch (JSONParseException ex) { String msg = "Invalid JSON data: " + ex.getMessage(); LOG.error(msg); throw new XPathException(this, MongodbModule.MONG0004, msg); } catch (XPathException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, ex.getMessage(), ex); } catch (MongoException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, MongodbModule.MONG0002, ex.getMessage()); } catch (Throwable t) { LOG.error(t.getMessage(), t); throw new XPathException(this, MongodbModule.MONG0003, t.getMessage()); } }
From source file:org.exoplatform.mongo.service.impl.MongoRestServiceImpl.java
License:Open Source License
@DELETE @Path("/databases/{dbName}/collections/{collName}") @Override/*from w w w . ja v a 2 s . c o m*/ public Response deleteCollection(@PathParam("dbName") String dbName, @PathParam("collName") String collName, @Context HttpHeaders headers, @Context UriInfo uriInfo, @Context SecurityContext securityContext) { if (shutdown) { return Response.status(ServerError.SERVICE_UNAVAILABLE.code()) .entity(ServerError.SERVICE_UNAVAILABLE.message()).build(); } Response response = null; String user = null; try { Credentials credentials = authenticateAndAuthorize(headers, uriInfo, securityContext); user = credentials.getUserName(); String dbNamespace = constructDbNamespace(credentials.getUserName(), dbName); if (mongo.getDatabaseNames().contains(dbNamespace)) { DB db = mongo.getDB(dbNamespace); authServiceAgainstMongo(db); if (db.getCollectionNames().contains(collName)) { DBCollection collection = db.getCollection(collName); collection.dropIndexes(); collection.drop(); response = Response.ok().build(); } else { response = Response.status(ClientError.NOT_FOUND.code()) .entity(collName + " does not exist in " + dbName).build(); } } else { response = Response.status(ClientError.NOT_FOUND.code()).entity(dbName + " does not exist").build(); } } catch (Exception exception) { response = lobException(exception, headers, uriInfo); } finally { updateStats(user, "deleteCollection"); } return response; }
From source file:org.exoplatform.mongo.service.impl.MongoRestServiceImpl.java
License:Open Source License
@DELETE @Path("/databases/{dbName}/collections") @Override/*from w w w . j a v a 2s .co m*/ public Response deleteCollections(@PathParam("dbName") String dbName, @Context HttpHeaders headers, @Context UriInfo uriInfo, @Context SecurityContext securityContext) { if (shutdown) { return Response.status(ServerError.SERVICE_UNAVAILABLE.code()) .entity(ServerError.SERVICE_UNAVAILABLE.message()).build(); } Response response = null; String user = null; try { Credentials credentials = authenticateAndAuthorize(headers, uriInfo, securityContext); user = credentials.getUserName(); String dbNamespace = constructDbNamespace(credentials.getUserName(), dbName); if (mongo.getDatabaseNames().contains(dbNamespace)) { DB db = mongo.getDB(dbNamespace); authServiceAgainstMongo(db); List<String> collections = new ArrayList<String>(); for (String collName : db.getCollectionNames()) { if (collName.equals(SYS_INDEXES_COLLECTION)) { continue; } collections.add(collName); DBCollection collection = db.getCollection(collName); collection.dropIndexes(); collection.drop(); } response = Response.ok("Deleted collections: " + collections).build(); } else { response = Response.status(ClientError.NOT_FOUND.code()).entity(dbName + " does not exist").build(); } } catch (Exception exception) { response = lobException(exception, headers, uriInfo); } finally { updateStats(user, "deleteCollections"); } return response; }
From source file:org.greenmongoquery.db.service.impl.MongoServiceImpl.java
License:Open Source License
@Override public void deleteCollection(String db, String collection, Mongo mongo) { DB dbs = mongo.getDB(db);//from w w w .jav a 2 s . c o m DBCollection coll = dbs.getCollection(collection); coll.drop(); }
From source file:org.jewzaam.mongo.command.MongoDropCommand.java
License:Open Source License
@Override protected Boolean run() throws Exception { try {//ww w . j ava 2 s .c om db.requestStart(); DBCollection coll = db.getCollection(collectionName); coll.drop(); } finally { db.requestDone(); } return Boolean.TRUE; }
From source file:org.modeshape.jcr.value.binary.MongodbBinaryStore.java
License:Apache License
@Override public void removeValuesUnusedLongerThan(long minimumAge, TimeUnit unit) { long deadline = new Date().getTime() - unit.toMillis(minimumAge); Set<String> keys = getStoredKeys(); for (String key : keys) { DBCollection content = db.getCollection(key); if (isExpired(content, deadline)) content.drop(); }/*from w w w . j a v a 2 s .co m*/ }
From source file:org.mongodb.demos.tailable.RealTimeAppServer.java
License:Apache License
private DBCollection createAndGetCappedCollection(String name) throws InterruptedException { DBCollection coll = db.getCollection(name); coll.drop(); DBObject options = new BasicDBObject("capped", true); options.put("size", 1000); coll = db.createCollection(name, options); coll.insert(BasicDBObjectBuilder.start("status", "initialized").get()); System.out.println("== capped collection created ==="); return coll;/*from ww w. ja v a2 s . c o m*/ }
From source file:org.mongoste.core.impl.mongodb.MongoUtil.java
License:Open Source License
public static void dropCollections(DB db) { for (String collection : db.getCollectionNames()) { if (collection.startsWith("system")) { continue; }// w w w. j a v a 2s .c om log.warn("Dropping collection {}.{}", db.getName(), collection); DBCollection col = db.getCollection(collection); col.drop(); } }
From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java
License:Apache License
public void purgeObjectModelFromDatabase() { DBCollection tpTable = database.getCollection(DatabaseNames.getTapPolicyTableName()); tpTable.drop(); DBCollection mcTable = database.getCollection(DatabaseNames.getMatchCriteriaTableName()); mcTable.drop();//from w w w .ja v a 2 s . c o m DBCollection seTable = database.getCollection(DatabaseNames.getSwitchEntryTableName()); seTable.drop(); DBCollection nhsTable = database.getCollection(DatabaseNames.getNextHopSwitchTableName()); nhsTable.drop(); DBCollection pcTable = database.getCollection(DatabaseNames.getPortChainTableName()); pcTable.drop(); DBCollection cdTable = database.getCollection(DatabaseNames.getCaptureDevTableName()); cdTable.drop(); DBCollection logTable = database.getCollection(DatabaseNames.getLoggerTableName()); logTable.drop(); }