Package org.jongo

Examples of org.jongo.MongoCollection


            public void modify(ObjectMapper mapper) {
                mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
            }
        }).build();
        Jongo jongo = new Jongo(getDatabase(), mapper);
        MongoCollection friends = jongo.getCollection("friends");
        Friend friend = new Friend("Peter", "31 rue des Lilas");
        friends.save(friend);

        friends.update(friend.getId()).with(new Friend("John"));

        Friend updated = friends.findOne().as(Friend.class);
        assertThat(updated.getName()).isEqualTo("John");
        assertThat(updated.getAddress()).isNull();
    }
View Full Code Here


    public static void startMongo() throws Exception {
        mongoResource = new MongoResource();
    }

    protected MongoCollection createEmptyCollection(String collectionName) throws UnknownHostException {
        MongoCollection col = jongo.getCollection(collectionName);
        col.drop();
        return col;
    }
View Full Code Here

        Jongo jongo = new Jongo(db, mapper);
        return jongo.getCollection("benchmark");
    }

    public static void injectFriendsIntoDB(int nbDocuments) throws UnknownHostException {
        MongoCollection collection = getCollectionFromJongo(new JacksonMapper.Builder().build());
        collection.drop();
        for (int i = 0; i < nbDocuments; i++) {
            collection.withWriteConcern(WriteConcern.SAFE).save(createFriend(i));
        }
        long count = collection.count();
        if (count < nbDocuments) {
            throw new RuntimeException("Not enough documents have been saved into db : expected " + nbDocuments + "/ saved: " + count);
        }
    }
View Full Code Here

                    checkNotNull(params.get(DB_URI),
                            DB_URI + " param is required"));
            Jongo jongo = new Jongo(new MongoClient(mongoClientURI).getDB(mongoClientURI.getDatabase()));
            try {
                Stopwatch stopwatch = Stopwatch.createStarted();
                MongoCollection collection = jongo.getCollection(given.getCollection());
                Iterable<String> items = Splitter.on("\n").trimResults().omitEmptyStrings().split(given.getData());
                int count = 0;
                for (String item : items) {
                    collection.insert(item);
                    count++;
                }
                System.out.printf("imported %s[%d] -- %s%n", given.getCollection(), count, stopwatch.stop().toString());
            } finally {
                jongo.getDatabase().getMongo().close();
View Full Code Here

        @Override
        public MongoCollection get() {
            final Mapper mapper = getMapper();

            MongoCollection mongoCollection = new MongoCollection(
                    collection.get().getDBCollection(),
                    new Mapper() {
                        @Override
                        public Marshaller getMarshaller() {
                            return mapper.getMarshaller();
View Full Code Here

            return collection.getName();
        }

        @Override
        public MongoCollection get() {
            MongoCollection mongoCollection = collection.get();
            if (tape != null) {
                tape.recordCollection(mongoCollection);
                mongoCollection = new MongoCollection(
                        mongoCollection.getDBCollection(),
                        new Mapper() {
                            @Override
                            public Marshaller getMarshaller() {
                                return mapper.getMarshaller();
                            }
View Full Code Here

TOP

Related Classes of org.jongo.MongoCollection

Copyright © 2018 www.massapicom. 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.