本文整理汇总了Java中com.mongodb.client.model.FindOneAndReplaceOptions类的典型用法代码示例。如果您正苦于以下问题:Java FindOneAndReplaceOptions类的具体用法?Java FindOneAndReplaceOptions怎么用?Java FindOneAndReplaceOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FindOneAndReplaceOptions类属于com.mongodb.client.model包,在下文中一共展示了FindOneAndReplaceOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findOneAndReplace
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
@Test
public void findOneAndReplace()
{
insertOneWithBulk();
Document replace = Document.parse(
"{\"car_id\":\"c7a\",\"name\":\"DELETEME\",\"color\":\"Redaa\",\"cno\":\"H116aa\",\"mfdcountry\":\"India\",\"speed\":53,\"price\":4.5}");
Assert.assertNotNull(coll.findOneAndReplace(Filters.eq("name", "DELETEME"), replace));
insertOneWithBulk();
Assert.assertNotNull(
coll.findOneAndReplace(Filters.eq("name", "DELETEME"), replace, new FindOneAndReplaceOptions()));
coll.deleteMany(Filters.eq("name", "DELETEME"));
}
示例2: doReplace
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
protected final FluentFuture<Optional<T>> doReplace(
final Constraints.ConstraintHost criteria,
final T document,
final FindOneAndReplaceOptions options) {
checkNotNull(criteria, "criteria");
checkNotNull(document, "document");
checkNotNull(options, "options");
return submit(new Callable<Optional<T>>() {
@Override
public Optional<T> call() throws Exception {
@Nullable T result = collection().findOneAndReplace(
convertToBson(criteria), // query
document,
options);
return Optional.fromNullable(result);
}
});
}
示例3: findOneAndReplace
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
@Override
public TDocument findOneAndReplace(Bson filter, TDocument arg1, FindOneAndReplaceOptions arg2)
{
OperationMetric metric = null;
if (MongoLogger.GATHERER.isEnabled())
{
List<String> keyValuePairs = MongoUtilities.getKeyValuePairs(filter);
String operationName = "Mongo : " + getNamespace().getCollectionName() + " : findOneAndReplace " +
MongoUtilities.filterParameters(filter).toString();
metric = startMetric(operationName, keyValuePairs);
addWriteKeyValuePairs(keyValuePairs);
if (MongoLogger.isRequestSizeMeasured())
{
metric.setProperty(CommonMetricProperties.REQUEST_SIZE_BYTES, Integer.toString(measureDocumentSize(arg1)));
}
addWriteConcern(metric);
addReadConcernAndPreference(metric);
}
TDocument retVal = collection.findOneAndReplace(filter, arg1, arg2);
stopMetric(metric, measureDocumentSizeIfResultSizeEnabled(retVal));
return retVal;
}
示例4: updateIfMatch
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
/**
* Updates the document if the document's ETAG is matching the given etag (conditional put).
* <p>
* Using this method requires that the document contains an "etag" field that is updated if
* the document is changed.
* </p>
*
* @param value the new value
* @param eTag the etag used for conditional update
* @param maxTime max time for the update
* @param timeUnit the time unit for the maxTime value
* @return {@link UpdateIfMatchResult}
*/
public UpdateIfMatchResult updateIfMatch(final V value,
final String eTag,
final long maxTime,
final TimeUnit timeUnit) {
final K key = keyOf(value);
if (key != null) {
final Bson query = and(eq(AbstractMongoRepository.ID, key), eq(ETAG, eTag));
final Document updatedETaggable = collectionWithWriteTimeout(maxTime, timeUnit).findOneAndReplace(query, encode(value), new FindOneAndReplaceOptions().returnDocument(AFTER));
if (isNull(updatedETaggable)) {
final boolean documentExists = collection()
.count(eq(AbstractMongoRepository.ID, key), new CountOptions().maxTime(maxTime, timeUnit)) != 0;
if (documentExists) {
return CONCURRENTLY_MODIFIED;
}
return NOT_FOUND;
}
return OK;
} else {
throw new IllegalArgumentException("Key must not be null");
}
}
示例5: setTimestampProperties
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
/**
* set timestamp properties (replace) for the given timestamp
*
* @param timestamp
* @param timestampProperties
*/
public void setTimestampProperties(final Long timestamp, BsonDocument timestampProperties) {
if (timestampProperties == null)
timestampProperties = new BsonDocument();
if (this instanceof ChronoVertex) {
graph.getVertexEvents().findOneAndReplace(
new BsonDocument(Tokens.VERTEX, new BsonString(this.id)).append(Tokens.TIMESTAMP,
new BsonDateTime(timestamp)),
Converter.makeTimestampVertexEventDocumentWithoutID(timestampProperties, this.id, timestamp),
new FindOneAndReplaceOptions().upsert(true));
} else {
ChronoEdge e = (ChronoEdge) this;
graph.getEdgeEvents().findOneAndReplace(
new BsonDocument(Tokens.OUT_VERTEX, new BsonString(e.getOutVertex().toString()))
.append(Tokens.LABEL, new BsonString(e.getLabel()))
.append(Tokens.TIMESTAMP, new BsonDateTime(timestamp))
.append(Tokens.IN_VERTEX, new BsonString(e.getInVertex().toString())),
Converter.makeTimestampEdgeEventDocumentWithoutID(timestampProperties, this.id, timestamp),
new FindOneAndReplaceOptions().upsert(true));
}
}
示例6: findOneAndReplaceWithOptions
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
@Override
public io.vertx.ext.mongo.MongoClient findOneAndReplaceWithOptions(String collection, JsonObject query, JsonObject replace, FindOptions findOptions, UpdateOptions updateOptions, Handler<AsyncResult<JsonObject>> resultHandler) {
requireNonNull(collection, "collection cannot be null");
requireNonNull(query, "query cannot be null");
requireNonNull(findOptions, "find options cannot be null");
requireNonNull(updateOptions, "update options cannot be null");
requireNonNull(resultHandler, "resultHandler cannot be null");
JsonObject encodedQuery = encodeKeyWhenUseObjectId(query);
Bson bquery = wrap(encodedQuery);
FindOneAndReplaceOptions foarOptions = new FindOneAndReplaceOptions();
foarOptions.sort(wrap(findOptions.getSort()));
foarOptions.projection(wrap(findOptions.getFields()));
foarOptions.upsert(updateOptions.isUpsert());
foarOptions.returnDocument(updateOptions.isReturningNewDocument() ? ReturnDocument.AFTER : ReturnDocument.BEFORE);
MongoCollection<JsonObject> coll = getCollection(collection);
coll.findOneAndReplace(bquery, replace, foarOptions, wrapCallback(resultHandler));
return this;
}
示例7: Replacer
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
protected Replacer(
Repository<T> repository,
T document,
Constraints.ConstraintHost criteria,
Constraints.Constraint ordering) {
super(repository);
this.document = checkNotNull(document, "document");
this.criteria = checkNotNull(criteria, "criteria");
this.ordering = checkNotNull(ordering, "ordering");
this.options = new FindOneAndReplaceOptions();
}
示例8: write
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
@Override
public Dataset write(Dataset dataset) {
// we populate this on first write and retain it thereafter
if (isBlank(dataset.getId())) {
dataset.setId(ObjectId.get().toString());
}
Observable<Document> observable =
getCollection()
.findOneAndReplace(
Filters.eq("id", dataset.getId()),
documentTransformer.transform(dataset),
new FindOneAndReplaceOptions().upsert(true).returnDocument(ReturnDocument.AFTER));
return documentTransformer.transform(Dataset.class, observable.toBlocking().single());
}
示例9: saveMapping
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
public SyncMap saveMapping(SyncMap map) {
// TODO : check why this is needed
if (map.getMapId() == null) {
map.setMapId(new ObjectId());
}
return syncMappings.findOneAndReplace(Filters.eq(SyncAttrs.ID, map.getMapId()), map,
new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER).upsert(true));
}
示例10: saveEvent
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
public SyncEvent saveEvent(SyncEvent event) {
if (event.getEventId() == null) {
event.setEventId(new ObjectId());
}
return syncEvents.findOneAndReplace(Filters.eq(SyncAttrs.ID, event.getEventId()), event,
new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER).upsert(true));
}
示例11: updateConnection
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
public SyncConnectionInfo updateConnection(SyncConnectionInfo connInfo) {
if(connInfo.getConnectionId() == null){
connInfo.setConnectionId(new ObjectId());
}
return connectionInfo.findOneAndReplace(
Filters.eq(String.valueOf(ConnectionInfoAttributes._id), connInfo.getConnectionId()), connInfo,
new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER).upsert(true));
}
示例12: toFindOneAndReplace
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
@Override
public FindOneAndReplaceOptions toFindOneAndReplace() {
final FindOneAndReplaceOptions options = new FindOneAndReplaceOptions();
options.bypassDocumentValidation(!validateDocuments);
setMaxTime(options);
setProjection(options);
options.returnDocument(ret);
setSort(options);
options.upsert(upsert);
return options;
}
示例13: findOneAndReplace
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
@Override
public Observable<TDocument> findOneAndReplace(final Bson filter, final TDocument replacement, final FindOneAndReplaceOptions options) {
return RxObservables.create(Observables.observe(new Block<SingleResultCallback<TDocument>>() {
@Override
public void apply(final SingleResultCallback<TDocument> callback) {
wrapped.findOneAndReplace(filter, replacement, options, callback);
}
}), observableAdapter);
}
示例14: findOneAndReplace
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
@Override
public Publisher<TDocument> findOneAndReplace(final Bson filter, final TDocument replacement, final FindOneAndReplaceOptions options) {
return new ObservableToPublisher<TDocument>(observe(new Block<SingleResultCallback<TDocument>>() {
@Override
public void apply(final SingleResultCallback<TDocument> callback) {
wrapped.findOneAndReplace(filter, replacement, options, callback);
}
}));
}
示例15: saveSession
import com.mongodb.client.model.FindOneAndReplaceOptions; //导入依赖的package包/类
public SyncUserSession saveSession(SyncUserSession userSession) {
return userSessionCollection.findOneAndReplace(
Filters.eq(String.valueOf(SessionAttributes._id), userSession.getSessionId()), userSession,
new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER).upsert(true));
}