Package com.mongodb

Examples of com.mongodb.DBCollection.createIndex()


        try {
            final DBCollection collection = mongoConnection.getDatabase().getCollection("graylog2_metrics");
            // don't hang on to the data for too long.
            final BasicDBObject indexField = new BasicDBObject("timestamp", 1);
            final BasicDBObject indexOptions = new BasicDBObject("expireAfterSeconds", 5 * 60);
            collection.createIndex(indexField, indexOptions);

            collection.insert(docs, WriteConcern.UNACKNOWLEDGED);
        } catch (Exception e) {
            LOG.warn("Unable to write graylog2 metrics to mongodb. Ignoring this error.", e);
        }
View Full Code Here


        }

        // Collection has not been cached yet. Do it now.
        DBCollection coll = getDatabase().getCollection("message_counts");

        coll.createIndex(new BasicDBObject("timestamp", 1));

        this.messageCountsCollection = coll;
        return coll;
    }
View Full Code Here

        // Create index if needed
        db.requestStart();
        DBCollection entities = db.getCollection( collectionName );
        if( entities.getIndexInfo().isEmpty() )
        {
            entities.createIndex( new BasicDBObject( IDENTITY_COLUMN, 1 ) );
        }
        db.requestDone();
    }

    private void loadConfiguration()
View Full Code Here

            @Override
            public Object doRun() throws IOException {
//                opts.put("key", keys);
//                return col.getDB().getCollection("system.indexes").insert(opts);
//                col.ensureIndex(keys, opts);
                col.createIndex(keys, opts);
                return new BasicDBObject("ok", 1);
            }

            @Override
            public String getNS() {
View Full Code Here

        // drop all the data in it
        coll.drop();

        // create an index on the "i" field
        coll.createIndex(new BasicDBObject("i", 1));

        // Geospatial query
        coll.createIndex(new BasicDBObject("loc", "2dsphere"));

        BasicDBList coordinates = new BasicDBList();
View Full Code Here

        // create an index on the "i" field
        coll.createIndex(new BasicDBObject("i", 1));

        // Geospatial query
        coll.createIndex(new BasicDBObject("loc", "2dsphere"));

        BasicDBList coordinates = new BasicDBList();
        coordinates.put(0, -73.97);
        coordinates.put(1, 40.77);
        coll.insert(new BasicDBObject("name", "Central Park")
View Full Code Here

                )
        );
        System.out.println(myDoc.get("name"));

        // create a text index on the "content" field
        coll.createIndex(new BasicDBObject("content", "text"));

        coll.insert(new BasicDBObject("_id", 0).append("content", "textual content"));
        coll.insert(new BasicDBObject("_id", 1).append("content", "additional content"));
        coll.insert(new BasicDBObject("_id", 2).append("content", "irrelevant content"));
View Full Code Here

        for (String columnName : columnList)
        {
            if (!indexNames.contains(columnName))
            {
                KunderaCoreUtils.printQuery("Create index on:" + columnName, showQuery);
                coll.createIndex(new BasicDBObject(columnName, order));
            }
        }
    }

    /*
 
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.