Java源码示例:com.mongodb.client.model.InsertOneOptions

示例1
@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
@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());
}
 
示例3
@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);
}
 
示例4
@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));
                }
            }));
}
 
示例5
@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
@Override
public Uni<InsertOneResult> insertOne(T t, InsertOneOptions options) {
    return Wrappers.toUni(collection.insertOne(t, options));
}
 
示例7
@Override
public Uni<InsertOneResult> insertOne(ClientSession clientSession, T t, InsertOneOptions options) {
    return Wrappers.toUni(collection.insertOne(clientSession, t, options));
}
 
示例8
@Override
public Publisher<Success> insertOne(final TDocument document) {
    return insertOne(document, new InsertOneOptions());
}
 
示例9
@Override
public Publisher<Success> insertOne(final ClientSession clientSession, final TDocument document) {
    return insertOne(clientSession, document, new InsertOneOptions());
}
 
示例10
/**
 * 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
/**
 * 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
/**
 * 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);
 
示例13
/**
 * 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);
 
示例14
/**
 * 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);