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());

    }
public static void main(final String[] args) {
        MongoClient mongoClient;

        if (args.length == 0) {
            
            mongoClient = new MongoClient();
        } else {
            mongoClient = new MongoClient(new MongoClientURI(args[0]));
        }

        
        DB database = mongoClient.getDB("mydb");


        
        DBCollection collection = database.getCollection("test");

        
        collection.drop();

        
        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());

    }
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 ( ) ) ; }
Run this main method to see the output of this quick example.

@param args takes an optional single argument for the connection string
Run this main method to see the output of this quick example .