com.mongodb.client.result.InsertOneResult#com.mongodb.client.model.InsertOneOptions源码实例Demo

下面列出了com.mongodb.client.result.InsertOneResult#com.mongodb.client.model.InsertOneOptions 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: quarkus   文件: BasicInteractionTest.java
@Test
void testDocumentInsertionWithOptions() {
    List<Integer> books = Arrays.asList(27464, 747854);
    DBObject person = new BasicDBObject("_id", "jo")
            .append("name", "Jo Bloggs")
            .append("address", new BasicDBObject("street", "123 Fake St")
                    .append("city", "Faketon")
                    .append("state", "MA")
                    .append("zip", 12345))
            .append("books", books);

    ReactiveMongoDatabase database = client.getDatabase(DATABASE);
    ReactiveMongoCollection<DBObject> collection = database.getCollection(randomAlphaString(8), DBObject.class);
    collection.insertOne(person, new InsertOneOptions().bypassDocumentValidation(true)).await().indefinitely();

    Optional<DBObject> maybe = collection.find().collectItems().first().await().asOptional().indefinitely();
    assertThat(maybe).isNotEmpty().containsInstanceOf(DBObject.class)
            .hasValueSatisfying(obj -> assertThat(obj.get("name")).isEqualTo("Jo Bloggs"));
}
 
源代码2 项目: rya   文件: MongoRyaInstanceDetailsRepository.java
@Override
public void initialize(final RyaDetails details) throws AlreadyInitializedException, RyaDetailsRepositoryException {
    // Preconditions.
    requireNonNull( details );

    if(!details.getRyaInstanceName().equals( instanceName )) {
        throw new RyaDetailsRepositoryException("The instance name that was in the provided 'details' does not match " +
                "the instance name that this repository is connected to. Make sure you're connected to the" +
                "correct Rya instance.");
    }

    if(isInitialized()) {
        throw new AlreadyInitializedException("The repository has already been initialized for the Rya instance named '" +
                instanceName + "'.");
    }

    // Create the document that hosts the details if it has not been created yet.
    db.createCollection(INSTANCE_DETAILS_COLLECTION_NAME, new CreateCollectionOptions());
    final MongoCollection<Document> col = db.getCollection(INSTANCE_DETAILS_COLLECTION_NAME);

    // Write the details to the collection.
    col.insertOne(MongoDetailsAdapter.toDocument(details), new InsertOneOptions());
}
 
@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>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<Success>>() {
                @Override
                public void apply(final com.mongodb.async.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>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<Success>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<Success> callback) {
                    wrapped.insertOne(clientSession.getWrapped(), document, options, voidToSuccessCallback(callback));
                }
            }));
}
 
源代码6 项目: quarkus   文件: ReactiveMongoCollectionImpl.java
@Override
public Uni<InsertOneResult> insertOne(T t, InsertOneOptions options) {
    return Wrappers.toUni(collection.insertOne(t, options));
}
 
源代码7 项目: quarkus   文件: ReactiveMongoCollectionImpl.java
@Override
public Uni<InsertOneResult> insertOne(ClientSession clientSession, T t, InsertOneOptions options) {
    return Wrappers.toUni(collection.insertOne(clientSession, t, options));
}
 
@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());
}
 
源代码10 项目: quarkus   文件: ReactiveMongoCollection.java
/**
 * 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 {@link Uni} completed successfully when the operation completes, or propagating a
 *         {@link com.mongodb.DuplicateKeyException} or {@link com.mongodb.MongoException} on failure.
 */
Uni<InsertOneResult> insertOne(T document, InsertOneOptions options);
 
源代码11 项目: quarkus   文件: ReactiveMongoCollection.java
/**
 * 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 {@link Uni} completed successfully when the operation completes, or propagating a
 *         {@link com.mongodb.DuplicateKeyException} or {@link com.mongodb.MongoException} on failure.
 */
Uni<InsertOneResult> insertOne(ClientSession clientSession, T document, InsertOneOptions options);
 
源代码12 项目: mongo-java-driver-rx   文件: MongoCollection.java
/**
 * 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);