use of com.mongodb.MongoClient in project mongo-hadoop by mongodb.
the class StandaloneMongoSplitterTest method setUp.
@BeforeClass
public static void setUp() {
MongoClient client = new MongoClient("localhost", 27017);
uri = new MongoClientURIBuilder().collection("mongo_hadoop", "splitter_test").build();
collection = client.getDB(uri.getDatabase()).getCollection(uri.getCollection());
collection.drop();
collection.createIndex("value");
for (int i = 0; i < 40000; i++) {
collection.insert(new BasicDBObject("_id", i).append("value", i));
}
}
use of com.mongodb.MongoClient in project mongo-hadoop by mongodb.
the class HiveQueryTest method setUp.
@Before
public void setUp() {
MongoClient client = new MongoClient("localhost:27017");
coll = client.getDatabase("mongo_hadoop").getCollection("hive_query");
for (int i = 0; i < 1000; ++i) {
coll.insertOne(new Document("i", i).append("j", i % 5));
}
}
use of com.mongodb.MongoClient in project mongo-hadoop by mongodb.
the class PigTest method testMongoStorageEnsureIndex.
@Test
public void testMongoStorageEnsureIndex() throws IOException, ParseException {
runScript("/pig/ensure_index.pig");
MongoClient client = new MongoClient("localhost:27017");
// There should be an index on the "last" field, ascending.
MongoCollection<Document> coll = client.getDatabase("mongo_hadoop").getCollection("ensure_indexes");
assertTrue("Should have the index \"last_1\"", indexExists(coll, "last_1"));
// Drop the index.
coll.dropIndex("last_1");
// Run the second pig script, which ensures a different index.
runScript("/pig/ensure_index_2.pig");
assertTrue("Should have the index \"first_1\"", indexExists(coll, "first_1"));
assertFalse("Should not have the index \"last_1\"", indexExists(coll, "last_1"));
}
use of com.mongodb.MongoClient 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.MongoClient 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());
}
Aggregations