@Override public void insertOne(TDocument arg0, InsertOneOptions arg1) { int writeSize = 0; OperationMetric metric = null; if (MongoLogger.GATHERER.isEnabled()) { List<String> keyValuePairs = createWriteKeyValuePairs(); String operationName = "Mongo : " + getNamespace().getCollectionName() + " : insertOne"; metric = startMetric(operationName, keyValuePairs); addWriteConcern(metric); if (MongoLogger.isResultSetSizeMeasured()) { writeSize = arg0.toString().length(); } } collection.insertOne(arg0, arg1); stopMetric(metric, writeSize); }
@Override public Observable<Success> insertOne(final TDocument document, final InsertOneOptions options) { return RxObservables.create(Observables.observe(new Block<SingleResultCallback<Success>>() { @Override public void apply(final SingleResultCallback<Success> callback) { wrapped.insertOne(document, options, voidToSuccessCallback(callback)); } }), observableAdapter); }
@Override public Publisher<Success> insertOne(final TDocument document, final InsertOneOptions options) { return new ObservableToPublisher<Success>(observe(new Block<SingleResultCallback<Success>>() { @Override public void apply(final SingleResultCallback<Success> callback) { wrapped.insertOne(document, options, voidToSuccessCallback(callback)); } })); }
@Override public Publisher<Success> insertOne(final ClientSession clientSession, final TDocument document, final InsertOneOptions options) { return new ObservableToPublisher<Success>(observe(new Block<SingleResultCallback<Success>>() { @Override public void apply(final SingleResultCallback<Success> callback) { wrapped.insertOne(clientSession, document, options, voidToSuccessCallback(callback)); } })); }
@BeforeClass public static void setup() { String mongoUrl = "mongodb://localhost:27017"; try { Properties prop = new Properties(); prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("mongo.properties")); mongoUrl = prop.getProperty("mongourl"); } catch (Exception ex) { ex.printStackTrace(); } // create an instance of client and establish the connection MongoClientURI connectionString = new MongoClientURI(mongoUrl); m1 = new MongoClient(connectionString); client = new ProfiledMongoClient(m1); db = client.getDatabase("testMongo"); coll = db.getCollection("car"); coll.insertOne(Document.parse( "{\"car_id\":\"c1\",\"name\":\"Audi\",\"color\":\"Black\",\"cno\":\"H110\",\"mfdcountry\":\"Germany\",\"speed\":72,\"price\":11.25}")); coll.insertOne(Document.parse( "{\"car_id\":\"c2\",\"name\":\"Polo\",\"color\":\"White\",\"cno\":\"H111\",\"mfdcountry\":\"Japan\",\"speed\":65,\"price\":8.5}")); coll.insertOne(Document.parse( "{\"car_id\":\"c3\",\"name\":\"Alto\",\"color\":\"Silver\",\"cno\":\"H112\",\"mfdcountry\":\"India\",\"speed\":53,\"price\":4.5}")); coll.insertOne( Document.parse( "{\"car_id\":\"c4\",\"name\":\"Santro\",\"color\":\"Grey\",\"cno\":\"H113\",\"mfdcountry\":\"Sweden\",\"speed\":89,\"price\":3.5}"), new InsertOneOptions()); gatherer = (TestLogMetricGatherer) MongoLogger.GATHERER; // assertEquals("Mongo : car : insertOne", gatherer.getLastMetric().getOperationName()); // assertEquals("car", gatherer.getLastMetric().getProperty(MongoProperties.MONGO_COLLECTION)); // assertEquals("testMongo", gatherer.getLastMetric().getProperty(MongoProperties.MONGO_DATABASE)); coll.insertMany(Arrays.asList( Document.parse( "{\"car_id\":\"c5\",\"name\":\"Zen\",\"color\":\"Blue\",\"cno\":\"H114\",\"mfdcountry\":\"Denmark\",\"speed\":94,\"price\":6.5}"), Document.parse( "{\"car_id\":\"c6\",\"name\":\"Alto\",\"color\":\"Blue\",\"cno\":\"H115\",\"mfdcountry\":\"India\",\"speed\":53,\"price\":4.5}"))); coll.insertMany( Arrays.asList( Document.parse( "{\"car_id\":\"c6\",\"name\":\"Alto\",\"color\":\"White\",\"cno\":\"H115\",\"mfdcountry\":\"India\",\"speed\":53,\"price\":4.5}"), Document.parse( "{\"car_id\":\"c6\",\"name\":\"Alto\",\"color\":\"Red\",\"cno\":\"H115\",\"mfdcountry\":\"India\",\"speed\":53,\"price\":4.5}")), new InsertManyOptions()); }
@Override public Publisher<Success> insertOne(final TDocument document) { return insertOne(document, new InsertOneOptions()); }
@Override public Publisher<Success> insertOne(final ClientSession clientSession, final TDocument document) { return insertOne(clientSession, document, new InsertOneOptions()); }
/** * Inserts the provided document. If the document is missing an identifier, the driver should generate one. * * @param document the document to insert * @param options the options to apply to the operation * @return an Observable with a single element indicating when the operation has completed or with either a * com.mongodb.DuplicateKeyException or com.mongodb.MongoException * @since 1.2 */ Observable<Success> insertOne(TDocument document, InsertOneOptions options);
/** * Inserts the provided document. If the document is missing an identifier, the driver should generate one. * * @param document the document to insert * @param options the options to apply to the operation * @return a publisher with a single element indicating when the operation has completed or with either a * com.mongodb.DuplicateKeyException or com.mongodb.MongoException * @since 1.2 */ Publisher<Success> insertOne(TDocument document, InsertOneOptions options);
/** * Inserts the provided document. If the document is missing an identifier, the driver should generate one. * * @param clientSession the client session with which to associate this operation * @param document the document to insert * @param options the options to apply to the operation * @return a publisher with a single element indicating when the operation has completed or with either a * com.mongodb.DuplicateKeyException or com.mongodb.MongoException * @mongodb.server.release 3.6 * @since 1.7 */ Publisher<Success> insertOne(ClientSession clientSession, TDocument document, InsertOneOptions options);