use of com.mongodb.BasicDBObject in project mongo-hadoop by mongodb.
the class MongoLoaderTest method testSimpleMap.
@Test
public void testSimpleMap() throws Exception {
//String userSchema = "m:[int]";
// Note: before pig 0.9, explicitly setting the type for
// map keys was not allowed, so can't test that here :(
String userSchema = "m:[]";
BasicDBObject obj = new BasicDBObject().append("k1", 1).append("k2", 2);
MongoLoader ml = new MongoLoader(userSchema);
Map m = (Map) BSONLoader.readField(obj, ml.getFields()[0]);
assertEquals(2, m.size());
assertEquals(1, m.get("k1"));
assertEquals(2, m.get("k2"));
}
use of com.mongodb.BasicDBObject in project mongo-hadoop by mongodb.
the class MongoLoaderTest method testBagThatIsNotABag.
@Test
public void testBagThatIsNotABag() throws IOException {
String userSchema = "b:{t:tuple(t1:chararray, t2:chararray)}";
BasicDBObject notABag = new BasicDBObject();
notABag.append("f1", new BasicDBObject().append("t1", "t11_value").append("t2", "t12_value"));
notABag.append("f2", new BasicDBObject().append("t1", "t21_value").append("t2", "t22_value"));
MongoLoader ml = new MongoLoader(userSchema);
Object result = BSONLoader.readField(notABag, ml.getFields()[0]);
assertNull(result);
}
use of com.mongodb.BasicDBObject in project mongo-hadoop by mongodb.
the class MongoOutputReader method readKeyValue.
@Override
public boolean readKeyValue() throws IOException {
// Actually, just read the value as the key is embedded.
try {
currentValue.readFields(in);
Object id = currentValue.getDoc().get("_id");
currentKey.setDoc(new BasicDBObject("_id", id));
// If successful we'll have an _id field
return id != null;
} catch (IndexOutOfBoundsException e) {
// No more data
LOG.info("No more data; no key/value pair read.");
return false;
}
}
use of com.mongodb.BasicDBObject 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.BasicDBObject in project mongo-java-driver by mongodb.
the class GridFSDBFile method remove.
/**
* Removes file from GridFS i.e. removes documents from files and chunks collections.
*/
void remove() {
fs.getFilesCollection().remove(new BasicDBObject("_id", id));
fs.getChunksCollection().remove(new BasicDBObject("files_id", id));
}
Aggregations