当前位置: 首页>>代码示例>>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;未经允许,请勿转载。