use of reactivestreams.helpers.SubscriberHelpers.PrintDocumentSubscriber in project mongo-java-driver by mongodb.
the class ClientSideEncryptionSimpleTour method main.
/**
* Run this main method to see the output of this quick example.
*
* Requires the mongodb-crypt library in the class path and mongocryptd on the system path.
* Assumes the schema has already been created in MongoDB.
*
* @param args ignored args
*/
public static void main(final String[] args) {
// This would have to be the same master key as was used to create the encryption key
final byte[] localMasterKey = new byte[96];
new SecureRandom().nextBytes(localMasterKey);
Map<String, Map<String, Object>> kmsProviders = new HashMap<String, Map<String, Object>>() {
{
put("local", new HashMap<String, Object>() {
{
put("key", localMasterKey);
}
});
}
};
String keyVaultNamespace = "admin.datakeys";
AutoEncryptionSettings autoEncryptionSettings = AutoEncryptionSettings.builder().keyVaultNamespace(keyVaultNamespace).kmsProviders(kmsProviders).build();
MongoClientSettings clientSettings = MongoClientSettings.builder().autoEncryptionSettings(autoEncryptionSettings).build();
MongoClient mongoClient = MongoClients.create(clientSettings);
MongoCollection<Document> collection = mongoClient.getDatabase("test").getCollection("coll");
ObservableSubscriber<Void> successSubscriber = new OperationSubscriber<>();
collection.drop().subscribe(successSubscriber);
successSubscriber.await();
ObservableSubscriber<InsertOneResult> insertOneSubscriber = new OperationSubscriber<>();
collection.insertOne(new Document("encryptedField", "123456789")).subscribe(insertOneSubscriber);
insertOneSubscriber.await();
ObservableSubscriber<Document> documentSubscriber = new PrintDocumentSubscriber();
collection.find().first().subscribe(documentSubscriber);
documentSubscriber.await();
// release resources
mongoClient.close();
}
use of reactivestreams.helpers.SubscriberHelpers.PrintDocumentSubscriber in project mongo-java-driver by mongodb.
the class QueryPrimer method lessThan.
@Test
public void lessThan() {
// @begin: less-than
// @code: start
FindPublisher<Document> publisher = db.getCollection("restaurants").find(new Document("grades.score", new Document("$lt", 10)));
// @code: end
// @pre: Iterate the results and apply a block to each resulting document
// @code: start
ObservableSubscriber<Document> documentSubscriber = new PrintDocumentSubscriber();
publisher.subscribe(documentSubscriber);
documentSubscriber.await();
// @code: end
// @pre: To simplify building queries the Java driver provides static helpers
// @code: start
db.getCollection("restaurants").find(lt("grades.score", 10));
// @code: end
// @end: less-than
}
use of reactivestreams.helpers.SubscriberHelpers.PrintDocumentSubscriber in project mongo-java-driver by mongodb.
the class QueryPrimer method queryFieldInArray.
@Test
public void queryFieldInArray() {
// @begin: query-field-in-array
// @code: start
FindPublisher<Document> publisher = db.getCollection("restaurants").find(new Document("grades.grade", "B"));
// @code: end
// @pre: Iterate the results and apply a block to each resulting document
// @code: start
ObservableSubscriber<Document> documentSubscriber = new PrintDocumentSubscriber();
publisher.subscribe(documentSubscriber);
documentSubscriber.await();
// @code: end
// @pre: To simplify building queries the Java driver provides static helpers
// @code: start
db.getCollection("restaurants").find(eq("grades.grade", "B"));
// @code: end
// @end: query-field-in-array
}
use of reactivestreams.helpers.SubscriberHelpers.PrintDocumentSubscriber in project mongo-java-driver by mongodb.
the class QueryPrimer method logicalOr.
@Test
public void logicalOr() {
// @begin: logical-or
// @code: start
FindPublisher<Document> publisher = db.getCollection("restaurants").find(new Document("$or", asList(new Document("cuisine", "Italian"), new Document("address.zipcode", "10075"))));
// @code: end
// @pre: Iterate the results and apply a block to each resulting document
// @code: start
ObservableSubscriber<Document> documentSubscriber = new PrintDocumentSubscriber();
publisher.subscribe(documentSubscriber);
documentSubscriber.await();
// @code: end
// @pre: To simplify building queries the Java driver provides static helpers
// @code: start
db.getCollection("restaurants").find(or(eq("cuisine", "Italian"), eq("address.zipcode", "10075")));
// @code: end
// @end: logical-or
}
Aggregations