當前位置: 首頁>>代碼示例>>Java>>正文


Java MongoCollection.drop方法代碼示例

本文整理匯總了Java中com.mongodb.client.MongoCollection.drop方法的典型用法代碼示例。如果您正苦於以下問題:Java MongoCollection.drop方法的具體用法?Java MongoCollection.drop怎麽用?Java MongoCollection.drop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.client.MongoCollection的用法示例。


在下文中一共展示了MongoCollection.drop方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: populateDatabase

import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
public static void populateDatabase(String[][] cellValues){
    MongoClient mongoClient = new MongoClient();
    MongoDatabase ddg = mongoClient.getDatabase("ddg");
    MongoCollection plants = ddg.getCollection("flowers");
    plants.drop();

    String[] keys = getKeys(cellValues);

    for (int i = 4; i < cellValues.length; i++){
        Map<String, String> map = new HashMap<String, String>();
        for(int j = 0; j < cellValues[i].length; j++){
            map.put(keys[j], cellValues[i][j]);
        }

        Document doc = new Document();
        doc.putAll(map);
        doc.append("thumbsUp", 0);
        doc.append("flowerVisits", 0);
        plants.insertOne(doc);
    }
}
 
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-2-spraguesanborn,代碼行數:22,代碼來源:ExcelParser.java

示例2: createBeds

import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
private static void createBeds(String[][] plants) {
    String[] keys = getKeys(plants);
    int bedCol = 1;
    for (int i = 0; i < keys.length; i++){
        if (keys[i].equals("gardenLocation")){
            bedCol = i;
            break;
        }
    }

    MongoClient mongoClient = new MongoClient();
    MongoDatabase ddg = mongoClient.getDatabase("ddg");
    MongoCollection beds = ddg.getCollection("beds");
    beds.drop();

    for (int i = 4; i < plants.length; i++){
        String currentBed = plants[i][bedCol];

        Bson filter = new Document("gardenLocation", currentBed);


        if (beds.count(filter) == 0 && !currentBed.equals("")) {
            Document doc = new Document("gardenLocation", currentBed);

            beds.insertOne(doc);
        }
    }
}
 
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-2-spraguesanborn,代碼行數:29,代碼來源:ExcelParser.java

示例3: clearAndPopulateDB

import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
@Before
public void clearAndPopulateDB() throws IOException {
    MongoClient mongoClient = new MongoClient();
    MongoDatabase db = mongoClient.getDatabase("test");
    MongoCollection<Document> userDocuments = db.getCollection("users");
    userDocuments.drop();
    List<Document> testUsers = new ArrayList<>();
    testUsers.add(Document.parse("{\n" +
            "                    name: \"Chris\",\n" +
            "                    age: 25,\n" +
            "                    company: \"UMM\",\n" +
            "                    email: \"[email protected]\"\n" +
            "                }"));
    testUsers.add(Document.parse("{\n" +
            "                    name: \"Pat\",\n" +
            "                    age: 37,\n" +
            "                    company: \"IBM\",\n" +
            "                    email: \"[email protected]\"\n" +
            "                }"));
    testUsers.add(Document.parse("{\n" +
            "                    name: \"Jamie\",\n" +
            "                    age: 37,\n" +
            "                    company: \"Frogs, Inc.\",\n" +
            "                    email: \"[email protected]\"\n" +
            "                }"));
    ObjectId samsId = new ObjectId();
    BasicDBObject sam = new BasicDBObject("_id", samsId);
    sam = sam.append("name", "Sam")
            .append("age", 45)
            .append("company", "Frogs, Inc.")
            .append("email", "[email protected]");
    samsIdString = samsId.toHexString();
    userDocuments.insertMany(testUsers);
    userDocuments.insertOne(Document.parse(sam.toJson()));

    // It might be important to construct this _after_ the DB is set up
    // in case there are bits in the constructor that care about the state
    // of the database.
    userController = new UserController("test");
}
 
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-2-spraguesanborn,代碼行數:41,代碼來源:UserControllerSpec.java

示例4: clearAndPopulateDB

import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
@Before
public void clearAndPopulateDB() throws IOException {
    MongoClient mongoClient = new MongoClient();
    MongoDatabase db = mongoClient.getDatabase("test");
    MongoCollection<Document> flowerDocuments = db.getCollection("flowers");
    flowerDocuments.drop();
    List<Document> testFlowers = new ArrayList<>();
    testFlowers.add(Document.parse("{\n" +
            "                    _id: \"id-1\",\n" +
            "                    commonName: \"tulip\",\n" +
            "                    cultivar: \"cltv-tulip\",\n" +
            "                    source: \"src-a\",\n" +
            "                    gardenLocation: \"loc-1\",\n" +
            "                    year: 2016\n" +
            "                }"));
    testFlowers.add(Document.parse("{\n" +
            "                    _id: \"id-2\",\n" +
            "                    commonName: \"lily\",\n" +
            "                    cultivar: \"cltv-lily\",\n" +
            "                    source: \"src-a\",\n" +
            "                    gardenLocation: \"loc-1\",\n" +
            "                    year: 2016\n" +
            "                }"));
    testFlowers.add(Document.parse("{\n" +
            "                    _id: \"id-3\",\n" +
            "                    commonName: \"daisy\",\n" +
            "                    cultivar: \"cltv-daisy\",\n" +
            "                    source: \"src-b\",\n" +
            "                    gardenLocation: \"loc-2\",\n" +
            "                    year: 2016\n" +
            "                }"));
    ObjectId roseId = new ObjectId();
    BasicDBObject rose = new BasicDBObject("_id", roseId);
    rose = rose.append("commonName", "rose")
            .append("cultivar", "cltv-rose")
            .append("source", "src-b")
            .append("gardenLocation", "loc-2")
            .append("year", 2016);
    roseIdString = roseId.toHexString();
    flowerDocuments.insertMany(testFlowers);
    flowerDocuments.insertOne(Document.parse(rose.toJson()));

    // It might be important to construct this _after_ the DB is set up
    // in case there are bits in the constructor that care about the state
    // of the database.
    flowerController = new FlowerController("test");
}
 
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-2-spraguesanborn,代碼行數:48,代碼來源:FlowerControllerSpec.java

示例5: dropCollection

import com.mongodb.client.MongoCollection; //導入方法依賴的package包/類
/**
 * 刪除集合
 *
 * @param collectionName 集合名
 */
public void dropCollection(String collectionName) {
    MongoCollection collection = sMongoDatabase.getCollection(collectionName);
    collection.drop();
}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:10,代碼來源:MongodbDataAccess.java


注:本文中的com.mongodb.client.MongoCollection.drop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。