Search in sources :

Example 11 with OperationSubscriber

use of reactivestreams.helpers.SubscriberHelpers.OperationSubscriber in project mongo-java-driver by mongodb.

the class InsertPrimer method insertADocument.

@Test
public void insertADocument() throws ParseException {
    // @begin: insert-a-document
    // @code: start
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
    ObservableSubscriber<InsertOneResult> insertOneSubscriber = new OperationSubscriber<>();
    db.getCollection("restaurants").insertOne(new Document("address", new Document().append("street", "2 Avenue").append("zipcode", "10075").append("building", "1480").append("coord", asList(-73.9557413, 40.7720266))).append("borough", "Manhattan").append("cuisine", "Italian").append("grades", asList(new Document().append("date", format.parse("2014-10-01T00:00:00Z")).append("grade", "A").append("score", 11), new Document().append("date", format.parse("2014-01-16T00:00:00Z")).append("grade", "B").append("score", 17))).append("name", "Vella").append("restaurant_id", "41704620")).subscribe(insertOneSubscriber);
    insertOneSubscriber.await();
// @code: end
// @post: The method does not return a result
// @end: insert-a-document
}
Also used : OperationSubscriber(reactivestreams.helpers.SubscriberHelpers.OperationSubscriber) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) InsertOneResult(com.mongodb.client.result.InsertOneResult) Document(org.bson.Document) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

OperationSubscriber (reactivestreams.helpers.SubscriberHelpers.OperationSubscriber)11 Document (org.bson.Document)10 InsertOneResult (com.mongodb.client.result.InsertOneResult)9 MongoClient (com.mongodb.reactivestreams.client.MongoClient)7 MongoClientSettings (com.mongodb.MongoClientSettings)4 DataKeyOptions (com.mongodb.client.model.vault.DataKeyOptions)4 InsertManyResult (com.mongodb.client.result.InsertManyResult)4 SecureRandom (java.security.SecureRandom)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 BsonBinary (org.bson.BsonBinary)4 Test (org.junit.Test)4 ClientEncryptionSettings (com.mongodb.ClientEncryptionSettings)3 ConnectionString (com.mongodb.ConnectionString)3 EncryptOptions (com.mongodb.client.model.vault.EncryptOptions)3 MongoDatabase (com.mongodb.reactivestreams.client.MongoDatabase)3 BsonString (org.bson.BsonString)3 PrintDocumentSubscriber (reactivestreams.helpers.SubscriberHelpers.PrintDocumentSubscriber)3 AutoEncryptionSettings (com.mongodb.AutoEncryptionSettings)2 MongoNamespace (com.mongodb.MongoNamespace)2