List of usage examples for com.mongodb.client MongoCollection drop
void drop();
From source file:my.beesyn.MongoConn.java
public void DropColl(String col_name) { MongoCollection drop_col = this.mdb.getCollection(col_name); drop_col.drop(); }
From source file:net.es.netshell.mongodb.MongoDBProvider.java
License:Open Source License
@Override public final void deleteCollection(String user, String name) { String collectionName = user + "_" + name; if (!KernelThread.currentKernelThread().isPrivileged()) { throw new SecurityException("delete collection - not authorized"); }//from www . ja v a 2s . com MongoCollection collection = this.db.getCollection(collectionName); if (collection == null) { throw new RuntimeErrorException(new Error("Could not delete collection " + name)); } collection.drop(); }
From source file:nl.syntouch.oracle.adapter.cloud.mongodb.sample.MongoDBSample.java
License:Apache License
public static void main(String[] args) { // connect to MongoDB at localhost:27017 MongoClient mongoClient = new MongoClient(); // switch to test db MongoDatabase database = mongoClient.getDatabase("test"); // drop test collection (note the collection will always be created by the getCollection command) MongoCollection<Document> collection = database.getCollection("test"); collection.drop(); // create a new collection collection = database.getCollection("test"); // create BSON document and save it Document doc = new Document().append("field1", "value1"); collection.insertOne(doc);//from w ww . j a v a 2s .com System.out.println(doc.toString()); Document queryDoc1 = new Document().append("_id", doc.get("_id")); System.out.println(collection.find(queryDoc1).first().toString()); Document queryDoc2 = new Document().append("field1", doc.get("field1")); System.out.println(collection.find(queryDoc2).first().toString()); }
From source file:org.apache.metamodel.mongodb.mongo3.MongoDbUpdateCallback.java
License:Apache License
protected void removeCollection(String name) { MongoCollection<Document> collection = getCollection(name); _collections.remove(name);//from ww w .j a v a2 s .c om collection.drop(); }
From source file:org.jboss.as.test.compat.nosql.mongodb.jaxrs.ClientResource.java
License:Open Source License
@GET @Produces({ "text/plain" }) public String get() { MongoCollection collection = null; Document query = null;// w w w .j a v a 2 s.c om try { collection = database.getCollection("company"); String companyName = "Acme products"; JsonObject object = Json.createObjectBuilder().add("companyName", companyName) .add("street", "999 Flow Lane").add("city", "Indiville").add("_id", companyName).build(); Document document = Document.parse(object.toString()); collection.insertOne(document); query = new Document("_id", companyName); FindIterable cursor = collection.find(query); Object dbObject = cursor.first(); return dbObject.toString(); } finally { if (query != null) { collection.drop(); } } }
From source file:org.jboss.as.test.compat.nosql.mongodb.modules.StatefulTestBean.java
License:Open Source License
public String addUserComment() { MongoCollection collection = null; Document query = null;//from w ww .j a v a 2 s . co m try { // add a comment from user Melanie String who = "Melanie"; Document comment = new Document("_id", who).append("name", who) .append("address", new BasicDBObject("street", "123 Main Street").append("city", "Fastville") .append("state", "MA").append("zip", 18180)) .append("comment", "MongoDB Is Web Scale"); // save the comment collection = database.getCollection("comments"); collection.insertOne(comment); // look up the comment from Melanie query = new Document("_id", who); FindIterable cursor = collection.find(query); Object userComment = cursor.first(); return userComment.toString(); } finally { collection.drop(); } }
From source file:org.jboss.as.test.compat.nosql.mongodb.modules.StatefulTestBean.java
License:Open Source License
public String addProduct() { MongoCollection collection = null; Document query = null;//from ww w . ja va 2s . c o m try { collection = injectedDatabase.getCollection("company"); String companyName = "Acme products"; JsonObject object = Json.createObjectBuilder().add("companyName", companyName) .add("street", "999 Flow Lane").add("city", "Indiville").add("_id", companyName).build(); Document document = Document.parse(object.toString()); collection.insertOne(document); query = new Document("_id", companyName); FindIterable cursor = collection.find(query); Object dbObject = cursor.first(); return dbObject.toString(); } finally { if (query != null) { collection.drop(); } } }
From source file:org.jboss.as.test.compat.nosql.mongodb.StatefulTestBean.java
License:Open Source License
public String addUserComment() { MongoCollection collection = null; Document query = null;/*from w w w . j a va2s . co m*/ try { // add a comment from user Melanie String who = "Melanie"; Document comment = new Document("_id", who).append("name", who) .append("address", new BasicDBObject("street", "123 Main Street").append("city", "Fastville") .append("state", "MA").append("zip", 18180)) .append("comment", "I really love your new website but I have a lot of questions about using NoSQL versus a traditional RDBMS. " + "I would like to sign up for your 'MongoDB Is Web Scale' training session."); // save the comment collection = database.getCollection("comments"); collection.insertOne(comment); // look up the comment from Melanie query = new Document("_id", who); FindIterable cursor = collection.find(query); Object userComment = cursor.first(); return userComment.toString(); } finally { collection.drop(); } }
From source file:org.jboss.as.test.compat.nosql.mongodb.StatefulTestBean.java
License:Open Source License
public String addProduct() { MongoCollection collection = null; Document query = null;// w w w . jav a2 s . c om try { collection = database.getCollection("company"); String companyName = "Acme products"; JsonObject object = Json.createObjectBuilder().add("companyName", companyName) .add("street", "999 Flow Lane").add("city", "Indiville").add("_id", companyName).build(); Document document = Document.parse(object.toString()); collection.insertOne(document); query = new Document("_id", companyName); FindIterable cursor = collection.find(query); Object dbObject = cursor.first(); return dbObject.toString(); } finally { if (query != null) { collection.drop(); } } }
From source file:org.jboss.as.test.compat.nosql.multiple.StatefulTestBean.java
License:Open Source License
public String addSalesComment() { MongoCollection collection = null; Document query = null;//from w ww .j a v a 2 s. c om try { // add a comment from Sales department String who = "InsideSalesTeam"; Document comment = new Document("_id", who).append("name", who) .append("address", new BasicDBObject("street", "inside sales").append("city", "internal") .append("state", "internal").append("zip", 99999)) .append("comment", "Need to sell sell sell"); // save the comment collection = database.getCollection("comments"); collection.insertOne(comment); query = new Document("_id", who); FindIterable cursor = collection.find(query); Object userComment = cursor.first(); return userComment.toString(); } finally { collection.drop(); } }