Search in sources :

Example 16 with MongoClientURI

use of com.mongodb.MongoClientURI in project mongo-hadoop by mongodb.

the class MongoUpdateStorage method setStoreLocation.

@Override
public void setStoreLocation(final String location, final Job job) throws IOException {
    final Configuration config = job.getConfiguration();
    if (!location.startsWith("mongodb://")) {
        throw new IllegalArgumentException("Invalid URI Format.  URIs must begin with a mongodb:// protocol string.");
    }
    MongoClientURI locURI = new MongoClientURI(location);
    LOG.info(String.format("Store location config: %s; for namespace: %s.%s; hosts: %s", config, locURI.getDatabase(), locURI.getCollection(), locURI.getHosts()));
    MongoConfigUtil.setOutputURI(config, locURI);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) MongoClientURI(com.mongodb.MongoClientURI)

Example 17 with MongoClientURI

use of com.mongodb.MongoClientURI in project mongo-hadoop by mongodb.

the class TablePropertiesTest method setUp.

@Before
public void setUp() {
    MongoClientURI clientURI = new MongoClientURI("mongodb://localhost:27017/mongo_hadoop.tabletest");
    MongoClient client = new MongoClient(clientURI);
    // Seed some documents into MongoDB.
    collection = client.getDatabase(clientURI.getDatabase()).getCollection(clientURI.getCollection());
    ArrayList<Document> documents = new ArrayList<Document>(1000);
    for (int i = 0; i < 1000; ++i) {
        documents.add(new Document("i", i));
    }
    collection.insertMany(documents);
    // Make sure table doesn't exist already.
    dropTable("props_file_test");
}
Also used : MongoClient(com.mongodb.MongoClient) MongoClientURI(com.mongodb.MongoClientURI) ArrayList(java.util.ArrayList) Document(org.bson.Document) Before(org.junit.Before)

Example 18 with MongoClientURI

use of com.mongodb.MongoClientURI in project mongo-java-driver by mongodb.

the class Decimal128LegacyAPIQuickTour method main.

/**
     * Run this main method to see the output of this quick example.
     *
     * @param args takes an optional single argument for the connection string
     */
public static void main(final String[] args) {
    MongoClient mongoClient;
    if (args.length == 0) {
        // connect to the local database server
        mongoClient = new MongoClient();
    } else {
        mongoClient = new MongoClient(new MongoClientURI(args[0]));
    }
    // get handle to "mydb" database
    DB database = mongoClient.getDB("mydb");
    // get a handle to the "test" collection
    DBCollection collection = database.getCollection("test");
    // drop all the data in it
    collection.drop();
    // make a document and insert it
    BasicDBObject doc = new BasicDBObject("name", "MongoDB").append("amount1", Decimal128.parse(".10")).append("amount2", new Decimal128(42L)).append("amount3", new Decimal128(new BigDecimal(".200")));
    collection.insert(doc);
    DBObject first = collection.findOne(QueryBuilder.start("amount1").is(new Decimal128(new BigDecimal(".10"))).get());
    Decimal128 amount3 = (Decimal128) first.get("amount3");
    BigDecimal amount2AsBigDecimal = amount3.bigDecimalValue();
    System.out.println(amount3.toString());
    System.out.println(amount2AsBigDecimal.toString());
}
Also used : MongoClient(com.mongodb.MongoClient) DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) MongoClientURI(com.mongodb.MongoClientURI) Decimal128(org.bson.types.Decimal128) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DB(com.mongodb.DB) BigDecimal(java.math.BigDecimal)

Example 19 with MongoClientURI

use of com.mongodb.MongoClientURI in project android-uploader by nightscout.

the class MongoUploaderTest method testReturnFalseWithInvalidURI.

@Test
public void testReturnFalseWithInvalidURI() {
    mongoUploader = new MongoUploader(preferences, new MongoClientURI("mongodb://foobar/db"), "collection", "dsCollection");
    AbstractUploaderDevice deviceStatus = mockDeviceStatus();
    assertThat(mongoUploader.uploadDeviceStatus(deviceStatus), is(false));
}
Also used : MongoClientURI(com.mongodb.MongoClientURI) AbstractUploaderDevice(com.nightscout.core.drivers.AbstractUploaderDevice) Test(org.junit.Test)

Example 20 with MongoClientURI

use of com.mongodb.MongoClientURI in project openhab1-addons by openhab.

the class MongoDBPersistenceService method connectToDatabase.

/**
     * Connects to the database
     */
private void connectToDatabase() {
    try {
        logger.debug("Connect MongoDB");
        this.cl = new MongoClient(new MongoClientURI(this.url));
        mongoCollection = cl.getDB(this.db).getCollection(this.collection);
        BasicDBObject idx = new BasicDBObject();
        idx.append(FIELD_TIMESTAMP, 1).append(FIELD_ITEM, 1);
        this.mongoCollection.createIndex(idx);
        logger.debug("Connect MongoDB ... done");
    } catch (Exception e) {
        logger.error("Failed to connect to database {}", this.url);
        throw new RuntimeException("Cannot connect to database", e);
    }
}
Also used : MongoClient(com.mongodb.MongoClient) BasicDBObject(com.mongodb.BasicDBObject) MongoClientURI(com.mongodb.MongoClientURI) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Aggregations

MongoClientURI (com.mongodb.MongoClientURI)64 MongoClient (com.mongodb.MongoClient)27 DBCollection (com.mongodb.DBCollection)12 BasicDBObject (com.mongodb.BasicDBObject)9 Test (org.junit.Test)9 MongoClientURIBuilder (com.mongodb.hadoop.util.MongoClientURIBuilder)8 Configuration (org.apache.hadoop.conf.Configuration)8 DBObject (com.mongodb.DBObject)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 InputSplit (org.apache.hadoop.mapreduce.InputSplit)6 DB (com.mongodb.DB)5 MongoDatabase (com.mongodb.client.MongoDatabase)5 MongoInputSplit (com.mongodb.hadoop.input.MongoInputSplit)5 IOException (java.io.IOException)5 MongoConnection (org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)5 Document (org.bson.Document)5 OptionParser (joptsimple.OptionParser)4 OptionSet (joptsimple.OptionSet)4 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)4