Package com.mongodb

Examples of com.mongodb.DB.createCollection()


            // Get an instance of Mongo
            Mongo m = new Mongo("localhost", 27017);
            DB db = m.getDB("personDB");
            personCollection = db.getCollection("persons");
            if (personCollection == null) {
                personCollection = db.createCollection("persons", null);
            }
        } catch (UnknownHostException ex) {
            Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
View Full Code Here


  @Test
  public void shouldCreateNewObjectInEmbeddedMongoDb() {
      // given
      DB db = mongo.getDB(DATABASE_NAME);
      DBCollection col = db.createCollection("testCollection", new BasicDBObject());
      //col.save(new BasicDBObject("testDoc", new Date()));
      BasicDBObject document = new BasicDBObject();
        document.put("id", 1001);
        document.put("msg", "hello world mongoDB in Java");
        col.insert(document);
View Full Code Here

            System.out.println(s);
        }

        // create a collection
        db = mongoClient.getDB("mydb");
        db.createCollection("testCollection", new BasicDBObject("capped", true)
                .append("size", 1048576));

        // List all collections
        for (String s : db.getCollectionNames()) {
            System.out.println(s);
View Full Code Here

            {
                db.getCollection(tableInfo.getTableName()).drop();

                KunderaCoreUtils.printQuery("Drop existing collection:" + tableInfo.getTableName(), showQuery);
            }
            DBCollection collection = db.createCollection(tableInfo.getTableName(), options);

            KunderaCoreUtils.printQuery("Create collection:" + tableInfo.getTableName(), showQuery);
            boolean isCappedCollection = isCappedCollection(tableInfo);
            if (!isCappedCollection)
            {
View Full Code Here

            DBObject options = setCollectionProperties(tableInfo);
            DB db = mongo.getDB(databaseName);
            DBCollection collection = null;
            if (!db.collectionExists(tableInfo.getTableName()))
            {
                collection = db.createCollection(tableInfo.getTableName(), options);
                KunderaCoreUtils.printQuery("Create collection:" + tableInfo.getTableName(), showQuery);
            }
            collection = collection != null ? collection : db.getCollection(tableInfo.getTableName());

            boolean isCappedCollection = isCappedCollection(tableInfo);
View Full Code Here

  }

  @Test
  public void shouldPersistAndFindBooks() {
    DB db = mongo.getDB("test-" + UUID.randomUUID());
    DBCollection collection = db.createCollection(BOOK_COLLECTION_NAME,
        new BasicDBObject());

    Set<String> collectionNames = db.getCollectionNames();
    assertThat(collectionNames, hasItem(BOOK_COLLECTION_NAME));
View Full Code Here

  }

  @Test
  public void shouldCountCategoriesUsingMapReduce() throws Exception {
    DB db = mongo.getDB("test-" + UUID.randomUUID());
    DBCollection collection = db.createCollection(BOOK_COLLECTION_NAME,
        new BasicDBObject());
    BasicDBObject book1 = new BasicDBObject()
        .append("title", BOOK1_TITLE)
        .append("author", AUTHOR_1)
        .append("categories",
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.