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);
}
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");
}
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());
}
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));
}
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);
}
}
Aggregations