List of usage examples for com.mongodb.client MongoCollection drop
void drop();
From source file:ch.hslu.dmg.InitDB.java
public void initProfs() { MongoClient mongo = new MongoClient("localhost", 27017); MongoDatabase database = mongo.getDatabase("unidb"); MongoCollection<Document> prof = database.getCollection("professoren"); prof.drop(); ArrayList<Document> profs = new ArrayList<>(); profs.add(new Document("PersNr", 2125).append("Name", "Sokrates").append("Rang", "C4").append("Raum", 226)); profs.add(new Document("PersNr", 2126).append("Name", "Russel").append("Rang", "C4").append("Raum", 232)); profs.add(/*from www . j av a 2 s. c o m*/ new Document("PersNr", 2127).append("Name", "Kopernikus").append("Rang", "C3").append("Raum", 310)); profs.add(new Document("PersNr", 2133).append("Name", "Popper").append("Rang", "C3").append("Raum", 52)); profs.add( new Document("PersNr", 2134).append("Name", "Augustinus").append("Rang", "C3").append("Raum", 309)); profs.add(new Document("PersNr", 2136).append("Name", "Curie").append("Rang", "C4").append("Raum", 36)); profs.add(new Document("PersNr", 2137).append("Name", "Kant").append("Rang", "C4").append("Raum", 7)); prof.insertMany(profs); mongo.close(); }
From source file:ch.hslu.dmg.InitDB.java
public void initStuds() { MongoClient mongo = new MongoClient("localhost", 27017); MongoDatabase database = mongo.getDatabase("unidb"); MongoCollection<Document> stud = database.getCollection("studenten"); stud.drop(); ArrayList<Document> studs = new ArrayList<>(); studs.add(new Document("Legi", 24002).append("Name", "Xenokrates").append("Semester", 18)); studs.add(//from w ww. j av a 2 s . c o m new Document("Legi", 25403).append("Name", "Jonas").append("Semester", 12).append("Hoeren", 5022)); studs.add( new Document("Legi", 26120).append("Name", "Fichte").append("Semester", 10).append("Hoeren", 5001)); studs.add(new Document("Legi", 26830).append("Name", "Aristoxenos").append("Semester", 8)); BasicDBList hoeren = new BasicDBList(); hoeren.add(5001); hoeren.add(4052); studs.add(new Document("Legi", 27550).append("Name", "Schopenhauer").append("Semester", 6).append("Hoeren", hoeren)); BasicDBList hoeren2 = new BasicDBList(); hoeren2.add(5041); hoeren2.add(5052); hoeren2.add(5216); hoeren2.add(5259); studs.add(new Document("Legi", 28106).append("Name", "Carnap").append("Semester", 3).append("Hoeren", hoeren2)); BasicDBList hoeren3 = new BasicDBList(); hoeren3.add(5001); hoeren3.add(5041); hoeren3.add(5049); studs.add(new Document("Legi", 29120).append("Name", "Theophrastos").append("Semester", 2).append("Hoeren", hoeren3)); BasicDBList hoeren4 = new BasicDBList(); hoeren4.add(5022); hoeren4.add(5001); studs.add(new Document("Legi", 29555).append("Name", "Feuerbach").append("Semester", 2).append("Hoeren", hoeren4)); stud.insertMany(studs); mongo.close(); }
From source file:ch.hslu.dmg.InitDB.java
public void initVorlesungen() { MongoClient mongo = new MongoClient("localhost", 27017); MongoDatabase database = mongo.getDatabase("unidb"); MongoCollection<Document> vorlesung = database.getCollection("vorlesungen"); vorlesung.drop(); ArrayList<Document> vorlesungen = new ArrayList<>(); vorlesungen.add(new Document("VorlNr", 5001).append("Titel", "Grundzge").append("SWS", 4) .append("GelesenVon", 2137)); vorlesungen.add(/* w w w . j a v a 2 s . c o m*/ new Document("VorlNr", 5041).append("Titel", "Ethik").append("SWS", 4).append("GelesenVon", 2125)); vorlesungen.add(new Document("VorlNr", 5043).append("Titel", "Erkentnistheorie").append("SWS", 3) .append("GelesenVon", 2126)); vorlesungen.add(new Document("VorlNr", 5049).append("Titel", "Maeeutik").append("SWS", 2) .append("GelesenVon", 2125)); vorlesungen.add( new Document("VorlNr", 4052).append("Titel", "Logik").append("SWS", 4).append("GelesenVon", 2125)); vorlesungen.add(new Document("VorlNr", 5052).append("Titel", "Wissenschaftstheorie").append("SWS", 3) .append("GelesenVon", 2126)); vorlesungen.add(new Document("VorlNr", 5216).append("Titel", "Bioethik").append("SWS", 2) .append("GelesenVon", 2126)); vorlesungen.add(new Document("VorlNr", 5259).append("Titel", "Der Wiener Kreis").append("SWS", 2) .append("GelesenVon", 2133)); vorlesungen.add(new Document("VorlNr", 5022).append("Titel", "Glaube und Wissen").append("SWS", 2) .append("GelesenVon", 2134)); vorlesungen.add(new Document("VorlNr", 4630).append("Titel", "Die 3 Kritiken").append("SWS", 4) .append("GelesenVon", 2137)); vorlesung.insertMany(vorlesungen); vorlesung.updateOne(eq("VorlNr", 5041), new Document("$set", new Document("Voraussetzung", vorlesung.find(eq("VorlNr", 5001)).iterator().next().get("_id")))); vorlesung.updateOne(eq("VorlNr", 5043), new Document("$set", new Document("Voraussetzung", vorlesung.find(eq("VorlNr", 5001)).iterator().next().get("_id")))); vorlesung.updateOne(eq("VorlNr", 5049), new Document("$set", new Document("Voraussetzung", vorlesung.find(eq("VorlNr", 5001)).iterator().next().get("_id")))); vorlesung.updateOne(eq("VorlNr", 5216), new Document("$set", new Document("Voraussetzung", vorlesung.find(eq("VorlNr", 5041)).iterator().next().get("_id")))); vorlesung.updateOne(eq("VorlNr", 5259), new Document("$set", new Document("Voraussetzung", vorlesung.find(eq("VorlNr", 5052)).iterator().next().get("_id")))); BasicDBList voraussetzungen = new BasicDBList(); voraussetzungen.add(vorlesung.find(eq("VorlNr", 5043)).iterator().next().get("_id")); voraussetzungen.add(vorlesung.find(eq("VorlNr", 5041)).iterator().next().get("_id")); vorlesung.updateOne(eq("VorlNr", 5052), new Document("$set", new Document("Voraussetzung", voraussetzungen))); mongo.close(); }
From source file:ch.hslu.dmg.InitDB.java
public void initAssistenten() { MongoClient mongo = new MongoClient("localhost", 27017); MongoDatabase database = mongo.getDatabase("unidb"); MongoCollection<Document> assistent = database.getCollection("assistenten"); assistent.drop(); ArrayList<Document> assistenten = new ArrayList<>(); assistenten.add(new Document("PersNr", 3002).append("Name", "Platon").append("Fachgebiet", "Ideenlehre") .append("Boss", 2125)); assistenten.add(new Document("PersNr", 3003).append("Name", "Aristoteles") .append("Fachgebiet", "Syllogistik").append("Boss", 2125)); assistenten.add(new Document("PersNr", 3004).append("Name", "Wittgenstein") .append("Fachgebiet", "Sprachtheorie").append("Boss", 2126)); assistenten.add(new Document("PersNr", 3005).append("Name", "Rhetikus") .append("Fachgebiet", "Planetenbewegung").append("Boss", 2127)); assistenten.add(new Document("PersNr", 3006).append("Name", "Newton") .append("Fachgebiet", "Keplersche Gesetze").append("Boss", 2127)); assistenten.add(new Document("PersNr", 3007).append("Name", "Spinoza") .append("Fachgebiet", "Gott und Natur").append("Boss", 2134)); assistent.insertMany(assistenten);//from ww w. ja v a2 s. co m mongo.close(); }
From source file:ch.hslu.dmg.InitDB.java
public void initPruefen() { MongoClient mongo = new MongoClient("localhost", 27017); MongoDatabase database = mongo.getDatabase("unidb"); MongoCollection<Document> pruefungen = database.getCollection("pruefungen"); pruefungen.drop(); ArrayList<Document> pruefung = new ArrayList<>(); pruefung.add(new Document("Legi", 28106).append("VorlNr", 5001).append("PersNr", 2126).append("Note", 1)); pruefung.add(new Document("Legi", 25403).append("VorlNr", 5041).append("PersNr", 2125).append("Note", 2)); pruefung.add(new Document("Legi", 27550).append("VorlNr", 4630).append("PersNr", 2137).append("Note", 2)); pruefungen.insertMany(pruefung);/*from w w w . j a v a 2 s . com*/ mongo.close(); }
From source file:cn.edu.hfut.dmic.webcollector.plugin.mongo.MongoDBManager.java
License:Open Source License
@Override public void merge() throws Exception { MongoCollection crawldb = database.getCollection("crawldb"); MongoCollection fetch = database.getCollection("fetch"); MongoCollection link = database.getCollection("link"); LOG.info("start merge"); /*?fetch*//*www . j a va 2s.co m*/ LOG.info("merge fetch database"); FindIterable<Document> findIte = fetch.find(); for (Document fetchDoc : findIte) { MongoDBUtils.updateOrInsert(crawldb, fetchDoc); } /*?link*/ LOG.info("merge link database"); findIte = link.find(); for (Document linkDoc : findIte) { MongoDBUtils.insertIfNotExists(crawldb, linkDoc); } LOG.info("end merge"); fetch.drop(); LOG.debug("remove fetch database"); link.drop(); LOG.debug("remove link database"); }
From source file:com.bc.fiduceo.db.MongoDbDriver.java
License:Open Source License
@Override public void clear() throws SQLException { final MongoCollection<Document> satelliteObservation = database.getCollection(SATELLITE_DATA_COLLECTION); satelliteObservation.drop(); }
From source file:com.erudika.para.persistence.MongoDBUtils.java
License:Apache License
/** * Deletes the main table from MongoDB.// www.jav a2 s. c o m * @param appid name of the {@link com.erudika.para.core.App} * @return true if deleted */ public static boolean deleteTable(String appid) { if (StringUtils.isBlank(appid) || !existsTable(appid)) { return false; } try { MongoCollection<Document> collection = getTable(appid); collection.drop(); } catch (Exception e) { logger.error(null, e); return false; } return false; }
From source file:com.ibm.research.mongotx.daytrader.Load.java
License:Open Source License
public static void dropCollections(TxDatabase client) throws Exception { MongoDatabase db = client.getDatabase(); for (String colName : new String[] { COL_HOLDING, COL_QUOTE, COL_ACCOUNT, COL_ACCOUNTPROFILE, COL_ORDER }) { out.println("drop " + colName); MongoCollection<Document> col = db.getCollection(colName); if (col != null) col.drop(); }//from ww w.j a v a 2s . c om }
From source file:com.imaginea.mongodb.services.impl.CollectionServiceImpl.java
License:Apache License
/** * Deletes a collection inside a database in mongo to which user is connected to. * * @param dbName Name of Database in which to insert a collection * @param collectionName Name of Collection to be inserted * @return Success if deletion is successful else throw exception * @throws DatabaseException throw super type of UndefinedDatabaseException * @throws ValidationException throw super type of * EmptyDatabaseNameException,EmptyCollectionNameException * @throws CollectionException throw super type of * UndefinedCollectionException,DeleteCollectionException *///from w w w.ja v a 2 s. com private void createCollection(CreateCollectionOptions options, MongoCollection<Document> selectedCollection, String selectedCollectionName, MongoDatabase db) { db.createCollection(selectedCollectionName + "_temp", options); MongoCollection<Document> tempCollection = db.getCollection(selectedCollectionName + "_temp"); MongoCursor<Document> cur = selectedCollection.find().iterator(); while (cur.hasNext()) { Document obj = cur.next(); tempCollection.insertOne(obj); } MongoNamespace namespace = selectedCollection.getNamespace(); selectedCollection.drop(); tempCollection.renameCollection(namespace); }